我有一个可复制的例子:
# I have 4 dataframes in a listy with a few observations that repeat themselves
df_1 <- data.frame(x = c(1, 2, 3, 4), y = c('apple', 'pineapple', 'orange', 'grape'))
df_2 <- data.frame(x = c(2, 3, 4, 5, 6, 7), y = c('watermelon', 'orange', 'halibut', 'apple', 'iron', 'grape'))
df_3 <- data.frame(x = c(2, 3, 4, 5, 6, 7, 9, 0), y = c('rock', 'pineapple', 'apple', 'tire', 'bomb', 'star', 'coconut', 'grape'))
df_4 <- data.frame(x = c(1, 4, 9), y = c('grape', 'apple', 'rock'))
# All inside a another list
df_list <- list(df_1, df_2, df_3, df_4)
我想要一个函数,它返回在每个rabrame中的y
列中重复的值,而不考虑该列中观察的顺序,因此函数的结果应该仅为:
[1] "apple" "grape"
我try 了reduce(intersect, big_list)
,但该函数没有捕获数据帧中所有重复的值.这可能是因为每列中重复值的位置不同,或者因为列表中的数据帧之间的列大小不相等.