How to remove rows that have NULL values in R

Below is the sample data and one manipulation. In the larger picture, I am reading in a bunch of excel files which are delineated by year and then taking only select columns (14 of 1000) and putting them into new data frames (df1,df2 for example). From there, I am combining these new data into one final data frame. My question is how I remove the rows in the final data frame that are populated with null values. I could filter but hoping to simply remove them in R and be done with them.

 testyear <-c(2010,2010,2010,2010,2011,2011,2011,2010)
 teststate<-c("CA", "Co", "NV", "NE", "CA", "CO","NV","NE")
 totalhousehold<-c(251,252,253,"NULL",301,302,303,"NULL")
 marriedhousehold <-c(85,86,87,"NULL",158,159,245,"NULL")


 test1<-data.frame(testyear,teststate,totalhousehold,marriedhousehold)


 testyear<-c(2012,2012,2012,2012)
 teststate<-c("WA","OR","WY","UT")
 totalhousehold<-c(654,650,646,641)
 marriedhousehold<-c(400,399,398,395)

 test2<-data.frame(testyear,teststate,totalhousehold,marriedhousehold)

 test3<-rbind(test1,test2)


Read more here: https://stackoverflow.com/questions/68462342/how-to-remove-rows-that-have-null-values-in-r

Content Attribution

This content was originally published by Tim Wilcox at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: