comparison - Comparing character strings in R -


i new r programming. have set of characters stored in variables x1 x25 instance x1 has values "v21", "v345", "v212" etc x2 x25 contain character values of similar variations e.g. "v45", "v67", "v556", "v21", "v44" , (x1 x25) of different lengths. these results analysis. want write function compare character values of x1 x25 , output results of characters appeared 5 times or more in values x1 x25. instance see result like:

"v21", "v67", "v556", "v45", "v44", "v212" 

if these characters appeared x1 x25. have been doing visual inspection , writing down results it's taking time of constrained of.

if possible (which know is), can me out please can learn it.

thanks

first, example setup:

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") 

having 25 variables stored separately can make difficult work them all. them use

vars <- paste0("x",1:25) corpus <- mget(vars) 

then corpus list containing of data. find want--all "v###" occur @ least 5 times--create table , perform boolean test on each element. extract names of values "v###".

valtable <- table(unlist(corpus)) keepers <- names(valtable[valtable >= 5]) keepers # [1] "v20"  "v22"  "v3"   "v4"   "v43"  "v556" "v56"  "v61"  

Comments