Reputation: 103
I'm currently in the process of writing a function in R. Apart of which I will be needing to define certain character's as NA.
Starting from the beginning
file <- readLines("/Users/debraragland/file.txt")
relines <- gsub("\\Frame.+$|\\Chain.+$|\\ATOM-WISE.+$", "", file)
Which leaves "" and " ". If I do each step at the prompt, I have to define and omit these as NAs twice
relines[relines==""] <- NA
relines <-na.omit(relines)
relines[relines==" "] <- NA
relines <- na.omit(relines)
Is there any way I can combine these into one, possible into an if statement?
Upvotes: 0
Views: 33
Reputation: 2400
I think this will do what you want:
relines[relines == "" | relines == " "] <- NA
relines <- na.omit(relines[!(relines == "" | relines == " ")])
Upvotes: 3