This is my first question here at Stack Overflow.
I have a data frame in R with over a hundred columns that is supposed to have duplicates. I can't use unique()
because I only want to remove row-adjacent duplicates in each column.
L = list(c("AL", "AL", "AI", "AH", "BK", "CD", "CE", "BT", "BP",
"BD", "BI", "AL"), c("AL", "AL", "AI", "AH", "BK", "AU", "BK",
"CD", "V", "CE", "CE"), c("AL", "AL", "AI", "AH", "AU", "BK",
"BQ"))
do.call(cbind, lapply(L, `length<-`, max(lengths(L))))
song 1 song 2 song 3
AL AL AL
AL AL AL
AI AI AI
AH AH AH
BK BK AU
CD AU BK
CE BK BQ
BT CD
BP V
BD CE
BI CE
AL
song 1 song 2 song 3
AL AL AL
AI AI AI
AH AH AH
BK BK AU
CD AU BK
CE BK BQ
BT CD
BP V
BD CE
BI
AL
I've seen previous answers that seems to work just fine for a single column.
The solution was
df = df[with(df, c(x[-1]!= x[-nrow(df)], TRUE)),]
I've seen rle
solutions, but they don't work.
Considering that the columns in my data frame have different lengths,
I would like to know if there is a way to loop through all the columns.