0

Attempting to delete rows containing specific strings in R (as shown in this answer: Delete rows containing specific strings in R)

Am consistently getting this error:

Error: Length of logical index vector must be 1 or 10 (the number of rows), not 47428

Any help would be most appreciated!

Reviews<- Reviews[!grep("dog", Reviews$Text)]
Bill P
  • 3,622
  • 10
  • 20
  • 32
  • 3
    It's going to be hard to impossible for anyone to help unless you include the actual code you used in your question, and probably with a reproducible example, so that we can run it ourselves and see exactly what's going on with the data it's being run on. – joran Sep 11 '18 at 19:40
  • 2
    It will be much easier for people to try to help you if you post your input (you can post the code you get from using `dput()`, and the code you have tried. – Kerry Jackson Sep 11 '18 at 19:44
  • Thank you. I've added the code. Still figuring out how to add a few rows from the dataframe, which is over 40,000 rows. – foreverstudent Sep 11 '18 at 19:56
  • In this case, I think it's easy to spot without the data (but in general, you should aim for including data). You're missing a comma: `Reviews[!grep("dog", Reviews$Text),]` Without the comma you're selecting from just the columns, of which I presume there are only 10. – joran Sep 11 '18 at 19:57
  • You might want to use the `grepl` function instead as that will evaluate to a boolean – SmitM Sep 11 '18 at 20:08
  • Thank you. The comma and switching to the grepl function helped fix this issue. – foreverstudent Sep 11 '18 at 20:12

1 Answers1

1

Try this:

Reviews<- Reviews[!grep("dog", Reviews$Text),]

If when you're trying to filter a dataset on a logical expression don't forget to include the comma to identify both the [rows, columns] of the matrix.

Cheers!