Advertisement
Guest User

Untitled

a guest
Feb 17th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. df <- data.frame('a'=c('a, b, c, d', 'a, c', 'b, d'), 'b'=c('a, d', 'a', 'a, d'))
  2.  
  3. a b
  4. 1 a, b, c, d a, d
  5. 2 a, c a
  6. 3 b, d a, d
  7.  
  8. a b c
  9. 1 a, b, c, d a, d a, d
  10. 2 a, c a a
  11. 3 b, d a, d d
  12.  
  13. df <- df %>%
  14. mutate(c=paste(c(intersect(unlist(strsplit(a, split=", ")), unlist(strsplit(b, split=", "))))))
  15.  
  16. Error in eval(substitute(expr), envir, enclos) :
  17. wrong result size (2), expected 3 or 1
  18.  
  19. df %>%
  20. mutate(c=length(c(intersect(unlist(strsplit(a, split=", ")), unlist(strsplit(b, split=", "))))))
  21.  
  22. a b c
  23. 1 a, b, c, d a, d 2
  24. 2 a, c a 2
  25. 3 b, d a, d 2
  26.  
  27. df %>% mutate(a_list=list(unlist(strsplit(a, split=", "))))
  28.  
  29. Error in eval(substitute(expr), envir, enclos) :
  30. not compatible with STRSXP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement