lundi 31 juillet 2017

Using 'ifelse' statements in R with quantitative criteria

New to SO. Don't kill me. I'm trying to figure out how to use 'ifelse' statements to add columns to a dataframe, based on a quantitative criteria related to a different column.

DTzips2[, politics := ifelse(pctr08zip > 0 & pctr08zip <= 0.33, "Liberal"),
                       ifelse(pctr08zip > 0.33 & pctr08zip <= 0.67, "Moderate"),
                              ifelse(pctr08zip > 0.67 & pctr08zip <=1, "Conservative")]



Error I've been getting is 'Provide either 'by' or 'keyby' but not both'. They also don't like the comma after 0.33. Help?

Aucun commentaire:

Enregistrer un commentaire