I have a list of dataframes called list
and it looks like this:
list[[1]]
X1 X2 X3 X4
a 1 b c
d 2 e f
g 3 h i
j 4 k l
list[[2]]
X1 X2 X3 X4
a 1 b c
d 2 e f
g 2 h i
j 3 k l
list[[3]]
X1 X2 X3 X4
a 1 b c
d 2 e f
g 3 h i
j 4 k l
I have been trying to use lapply to loop through the list and print out all the duplicates in column X2 of each dataframe.
I'm not able to figure this out. Would appreciate any help. Thanks.
I've tied
lapply(list, function(i) {
if(length(unique(i[X2])) != length(i[X2])) {
print(i[X2][duplicated(i[X2]))
} else {
print("No duplicates")
}
})