首先,一个示例设置:
x1 <- c("v21", "v67", "v556", "v45", "v44", "v212")
x2 <- c("v21", "v67", "v556", "v45", "v44", "v212")
x3 <- c("v21", "v67", "v556", "v45", "v44", "v212")
x4 <- c("v21", "v67", "v556", "v45", "v44", "v212")
x5 <- c("v22", "v61", "v56", "v3", "v4", "v20")
x6 <- c("v22", "v61", "v56", "v3", "v4", "v20")
x7 <- c("v22", "v61", "v56", "v3", "v4", "v20")
x8 <- c("v22", "v61", "v56", "v3", "v4", "v20")
x9 <- c("v22", "v61", "v56", "v3", "v4", "v20")
x10 <- c("v556")
x11 <- c("v12","v345","v55")
x12 <- c("v12","v345","v55")
x13 <- c("v12","v345","v55")
x14 <- c("v12","v345","v55")
x15 <- c("v1", "v51", "v43", "v43")
x16 <- c("v1", "v51", "v43", "v43")
x17 <- c("v1", "v51", "v43", "v43")
x18 <- c("v1", "v51", "v43", "v43")
x19 <- c("v200")
x20 <- c("v200")
x21 <- c("v200")
x22 <- c("v39","v556","v41")
x23 <- c("v39","v556","v41")
x24 <- c("v39","v556","v41")
x25 <- c("v39","v556","v41")
单独存储 25 个变量可能会使它们难以全部使用。让他们一起使用
vars <- paste0("x",1:25)
corpus <- mget(vars)
然后corpus
是一个包含所有数据的列表。要找到你想要的——所有出现至少 5 次的“v###”——创建一个表,然后对每个元素执行布尔测试。提取这些值的名称以获得“v###”。
valTable <- table(unlist(corpus))
keepers <- names(valTable[valTable >= 5])
keepers
# [1] "v20" "v22" "v3" "v4" "v43" "v556" "v56" "v61"