I could not figure it out why |
logical operator doesn't worked.
set.seed(123)
add <- sample(rep(letters[1:4],times=4))
value = c(rep(runif(4),times=4))
id <- rep(c("Good","Bad","ugly","dirty"),each=4)
df <- data.frame(add,value,id=sample(id))
add value id
1 a 0.24608773 dirty
2 d 0.04205953 ugly
3 b 0.32792072 ugly
4 c 0.95450365 dirty
5 a 0.24608773 Bad
6 a 0.04205953 ugly
7 b 0.32792072 Bad
8 a 0.95450365 ugly
9 d 0.24608773 Good
10 d 0.04205953 Good
11 b 0.32792072 dirty
12 c 0.95450365 Bad
13 d 0.24608773 dirty
14 b 0.04205953 Good
15 c 0.32792072 Good
16 c 0.95450365 Bad
I try to add new column label
with |
,
df_clas <- df%>%
mutate(label=ifelse(id=='dirty|ugly'&value<0.9,'Animal',''))
I am getting label column empty.
I also tried
mutate(label=ifelse(id=='dirty'|'ugly'&value<0.9,'Animal',''))
Error in mutate_impl(.data, dots) : operations are possible only for numeric, logical or complex types
But When I tried,
mutate(label=ifelse(id=='dirty'|id=='ugly'&value<0.9,'Animal',''))
it works but I want to use 'id'
only once in the beginning of the conditions. How can I do that ?