mardi 9 janvier 2018

R: ifelse statement on dataframe

d1 <- data.frame(y1 = c("A","B","C"), y2 = c(1, 2, 3), y3 = c(4, 5, 6))

I want to make all values < 3 to zero.

I did this:

d2 <- ifelse(d1[,2:3] > 3,  d1[,2:3], 0)

However, it returns me a list. I need the exact dataframe but with values < 3 as zeros.

Aucun commentaire:

Enregistrer un commentaire