samedi 14 novembre 2020

error of unused argument(T) in ifelse in R

I try to reverse the boolean vector with ifelse:

labels <- disease%>% 
  select(humansAffected)%>%
  is.na()%>%
  ifelse(T, F,T)

However, I got an error: Error in ifelse(., labels == T, F, T) : unused argument (T) even if I changed to :

labels <- disease%>% 
    select(humansAffected)%>%
    is.na()%>%
    ifelse(labels==T,"FALSE","TRUE")

it shows error: Error in ifelse(., labels == T, "FALSE", "TRUE") : unused argument ("TRUE").

But when I write like this, I got the result I want:

labels <- disease%>% 
  select(humansAffected)%>%
  is.na()
ifelse(labels==T,F,T)

I want to know why I can't get the answer when I write them together by using %>%?

Aucun commentaire:

Enregistrer un commentaire