Hello, I am trying to manipulate a conditional string outputted from SAS into the right format for a conditional statement in R. Here is an example of the conditional outputted from SAS:
. < var1_a<=80 and var2_a>50.8
I've written a function that handles some of the transformation necessary:
conditonalsub <- function(x) {
subnew <- gsub("<=", " <= ", x)
subnew <- gsub(">=", " >= ", subnew)
subnew <- gsub(">", " > ", subnew)
subnew <- gsub("and", "&", subnew)
subnew <- gsub("\\.\\s", "NA ", subnew)
return(subnew)
which produces the following string:
NA < var1_a <= 80 & var2_a > 50.8
I am using these conditional statements to subset the observations of a data frame. So in this example I want R to select all observations with var1_a values that are either missing or less than or equal to 80 AND have var2_a greater than 50.8. How can I modify the above function so that I get a conditional statement that is able to take missing values like the var1_a portion of the conditional statement above? My guess is the format of the new conditional statement would look something like this?
(var1_a == NA | var1_a <= 80) & (var2_a > 50.8)