How to set a column value based on values in another column in R -
i trying add new column based on values in column. (basically if other column missing or 0, set new value 0 or 1)
what's wrong code below?
times=nrow(eachfile) for(i in 1:times) {eachfile$salescyclen0[i] <- ifelse(eachfile$r[i]==na | eachfile$r[i]==0,0,1 ) } table(eachfile$salescyclen0)
as long have tested column contains 0, 1 , na do:
eachfile$salescyclen0 <- 1 eachfile$salescyclen0[is.na(eachfile$r) | eachfile$r==0] <- 0
Comments
Post a Comment