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
Post a Comment