R language Loop If staments -


i have dataset of 6 column , 4.5 millions rows. write logical check if in fifth column there values zeroes, put 1 in sixth column. explain me how construct algorithm this? in fifth column found have cells 0 value. want perform if in fifth column have 0 values put 1 in sixth column , if not put 0?

you can use ifelse function :

df[,6] = ifelse(df[,5] == 0, 1, df[,6]) 

or without ifelse:

df[,6] <- as.integer(df[,5] == 0) 

where df data.frame.

the second approach put 0's column 6 whenever column 5 not 0 , 1s otherwise.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -