[R] shrink list by mathed entries

Soeren.Vogel at eawag.ch Soeren.Vogel at eawag.ch
Fri Nov 13 17:19:13 CET 2009


Hello

a <- c("Mama", "Papa", "Papa; Mama", "", "Sammy; Mama; Papa")
a <- strsplit(a, "; ")
mama <- rep(F, length(a))
mama[sapply(a, function(x) { sum(x=="Mama") }, simplify=T) > 0] <- T
papa <- rep(F, length(a))
papa[sapply(a, function(x) { sum(x=="Papa") }, simplify=T) > 0] <- T
# ... more variables

... produces the variables "mama" and "papa" correctly. But how do I  
remove all "Mama" list entries in "a" in the same run, that is, shrink  
the list by what was already matched?

Thank you for your help!

Sören Vogel


-- 
Sören Vogel, Dipl.-Psych. (Univ.), PhD-Student, Eawag, Dept. SIAM
http://www.eawag.ch, http://sozmod.eawag.ch




More information about the R-help mailing list