I am just starting out in the process of clearing strings with R and still recognized a ton. The part of the current project that I'm stuck (I think) is pretty much related to referring to the values in the list. I am trying to use the split-apply-comb method and am having problems returning to the form of data that I want at the end.
I tried various permutations which(), unlist()and any()but just can't get what I'm looking for, so I'm sitting asking for your help. Thank.
I have a long list of lines ...
> dput(x)
list(c("ACETATE", "RINGERS"), "ACETYLCYSTEINE", c("ACETYLSALICYLIC",
"ACID"), "ADIRAMYCIN", c("ADRENALINE", "00003901"), "ALEMTUZUMAB")
> x
[[1]]
[1] "ACETATE" "RINGERS"
[[2]]
[1] "ACETYLCYSTEINE"
[[3]]
[1] "ACETYLSALICYLIC" "ACID"
[[4]]
[1] "ADIRAMYCIN"
[[5]]
[1] "ADRENALINE" "00003901"
[[6]]
[1] "ALEMTUZUMAB"
I wrote simple code to remove certain words from the list ...
bad.words <- c("ACID", "BASE", "HYDROCHOLIRDE", "STUFF")
a <- lapply(x, function(x) x %in% bad.words)
> a
[[1]]
[1] FALSE FALSE
[[2]]
[1] FALSE
[[3]]
[1] FALSE TRUE
[[4]]
[1] FALSE
[[5]]
[1] FALSE FALSE
[[6]]
[1] FALSE
I would like to be able to create zso that it is xwithout bad.words.
> z
[[1]]
[1] "ACETATE" "RINGERS"
[[2]]
[1] "ACETYLCYSTEINE"
[[3]]
[1] "ACETYLSALICYLIC"
[[4]]
[1] "ADIRAMYCIN"
[[5]]
[1] "ADRENALINE" "00003901"
[[6]]
[1] "ALEMTUZUMAB"