I have some columns in a dataframe that are character variables. The below gives a two-row example of what the columns I’m interested in might look like:
a <- rep('Agree', 20)
b <- rep(c('Disagree', 'Agree'), 10)
dat <- data.frame(rbind(a,b), stringsAsFactors = FALSE)
I want to identify all the rows where each of the columns has the same value. For example, using dplyr mutate, I would like to create a new variable called ‘allSame’ where the value in the first row of 'dat' would be ‘yes’ and the value in the second row would be ‘no’.
I would also like to do this indexing the columns by number rather than name, because some of the variables have very long names and there are multiple sets of columns in the dataframe that I’d like to do this for.