R - How to compare values across more than two columns -


i'm trying write code compare values of several columns, , dont know ahead of time how many columns have. data this:

x   val1    val2    val3    val4   1        1        1       2 b   na       2        2       2 c   3        3        3       3 

the code should return fail rows , b, , pass row c, needs able handle changing number of columns. can't figure out how without nesting couple of loops, there has way use apply or sapply iterate through columns 2: length(df)

edit: want see if values (which numbers) equal

assuming first column excluded comparison , other columns not, can try:

which(rowsums(df[,2]==df[,3:ncol(df)])==(ncol(df)-2)) 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -