0

My first question here and I am not very experienced, however I hope this question is easy enough to answer since I only want to know if what I describe in the title is possible.

I have multiple dataframes taken from online capacity tests participants did.

For all Items I have response, score, and durationvariables among others.

Now I want to delete rows where all responsevariables are NA. So I can't just use a command to delete rows with where all is NA but there are also to many columns to do it by hand. And I also want to keep the dataframe together while doing it in order to really drop the complete rows, so just extracting all responsevariables doesn't sound like a good option.

However, besides a 3digit number based on the specific items the responsevariablenames are basically the same.

So instead of writing a very long impractical line mentioning all responsevariables and to drop the row if they all contain NA is there a way to not use the full anme of a variable but only use the end of the name for example so R checks the condition for all variables ending that way?

simplified e.g: instead of

newdf <- olddf[!(olddf$item123response != NA & olddf$item131response != NA & etc),]

Can I just do something like newdf <- olddf[!(olddf$xxxresponse != NA),] ?

I tried to google an answer but I didn't know how to frame my question effectively.

Thanks in advance!

  • You should be using something like `is.na()` to check for `NA` values. [See here](https://stackoverflow.com/questions/4862178/remove-rows-with-all-or-some-nas-missing-values-in-data-frame) for one possible solution. – Tim Biegeleisen Jan 29 '20 at 13:34

1 Answers1

0

Try This

newdf <- olddf[complete.cases(olddf[, grep('response', names(olddf))]), ]