I am new to this community and hoping to solve this problem.
I have a dataframe that looks as follows:
df <- data.frame(id=c(1,2,3,4),id2=c("x","y","z","a"),value1=c(1,2,3,4),value2=c(1,2,3,4),value3=c(1,1,3,4),value4=c(1,2,3,4),value5=c(1,2,3,"ab"))
I want to check if value1,value2, value3 and value4 are all the same. I am able to get this to work with the following code:
comp4 <- df[,3:7] %>%
rowwise %>%
mutate(same =n_distinct(unlist(cur_data())) == 1) %>%
ungroup
However, I end up losing the id1 and id2 columns in the data frame. How do I solve this by keeping id1 and id2.