0

I have a dataset with weekly number of lucky days for some of those weekly values i have values greater than 7 which must be a mistake.

Therefore what I want to do is to delete rows which have a value greater than 7 in one of the multiple columns. Those columns are column 21 to 68. What I have tried so far is this:

new_df <- subset(df, 21:68 <= 7) 

This leaves me with an completely empty new_df.

I know there is a option that goes like this:

new_df <- subset(df, b != 7 & d != 7)

But I feel like there must be a more elegant way than to name every single column which I want to refer to. Do I need to use square brackets or sth. like that? There is no Error message when computing the above mentioned command. The referred values are numerical.

Can someone help?

  • Does this answer your question? [Subset multiple columns in R - more elegant code?](https://stackoverflow.com/questions/9641458/subset-multiple-columns-in-r-more-elegant-code) – Giora Simchoni Mar 06 '22 at 08:18
  • I have seen that example but there rows are kept when criteria is fullfilled in one column. But what I need is to delete rows when criteria is fullfilled in one column. i did not now how to invert that – getting_there Mar 06 '22 at 08:32
  • Can you provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of your data? You can edit your question and paste the result of `dput(df)` there. Without your data, it's hard to guess what you want. If it's possible, also include a few lines of your desired output :) – benson23 Mar 06 '22 at 08:56
  • Removing rows with values > 7 only hides the problem without actually addressing it. Clearly there’s a problem in whatever generated these data. Values with > 7 weekdays alerted you to the problem, but other values could very well be wrong too (e.g, 6 weekdays when the correct value should be 4). I would try to figure out what’s causing the errors upstream. – zephryl Mar 06 '22 at 14:03

0 Answers0