Reputation: 495
I wrote this function in R
match <- followers %>%
+ mutate(x= ifelse(followers$screen_name %in% xnames$screen_name, 1, 0),y= ifelse(followers$screen_name %in% ynames$screen_name, 1, 0))
but i get this error and i can't solve it
Error in mutate_(.data, .dots = compat_as_lazy_dots(...)) :
argument ".data" is missing, with no default
here more information about the data
> str(xnames)
'data.frame': 5000 obs. of 1 variable:
$ screen_name: chr "27khT5dIkDpu4hl" "M8ibrahem" "IBRAHEM87711" "ryooon85" ...
> str(ynames)
'data.frame': 5000 obs. of 1 variable:
$ screen_name: chr "rosebiose" "S7q0QTdIk8SLcNm" "DleGQquoaUGxQzn" "RxafjLONGO6UgS8" ...
str(followers)
'data.frame': 9925 obs. of 1 variable:
$ screen_name: chr "27khT5dIkDpu4hl" "M8ibrahem" "IBRAHEM87711" "ryooon85" ...
here is sample of the data
> head(xnames)
screen_name
1 27khT5dIkDpu4hl
2 M8ibrahem
3 IBRAHEM87711
4 ryooon85
5 sqrr1233
6 3ram16
> head(ynames)
screen_name
1 rosebiose
2 S7q0QTdIk8SLcNm
3 DleGQquoaUGxQzn
4 RxafjLONGO6UgS8
5 YlirzqF0N9EfeOY
6 AL_3GEEEED
> head(followers)
screen_name
1 27khT5dIkDpu4hl
2 M8ibrahem
3 IBRAHEM87711
4 ryooon85
5 sqrr1233
6 3ram16
I tried also to convert the type of the columns to factor but still gives me the same error
thank you
Upvotes: 0
Views: 5973
Reputation: 9485
Here a solution with fake data, I advice you to use also dplyr::if_else
rather than ifelse
, it's safer:
library(dplyr)
followers <- data.frame(screen_name = c(' 27khT5dIkDpu4hl','M8ibrahem','IBRAHEM87711','ryooon85','sqrr1233','3ram16'))
xnames <- data.frame(screen_name = c('27khT5dIkDpu4hl','IBRAHEM87711','ryooon85','sqrr1233','3ram16'))
ynames <- data.frame(screen_name = c('rosebiose','S7q0QTdIk8SLcNm','DleGQquoaUGxQzn','RxafjLONGO6UgS8','YlirzqF0N9EfeOY','AL_3GEEEED'))
followers %>% mutate(x = if_else(screen_name %in% xnames$screen_name,1,0),
y = if_else(screen_name %in% ynames$screen_name,1,0))
screen_name x y
1 27khT5dIkDpu4hl 0 0
2 M8ibrahem 0 0
3 IBRAHEM87711 1 0
4 ryooon85 1 0
5 sqrr1233 1 0
6 3ram16 1 0
Upvotes: 1