I have a dataframe m
and I want to remove all the rows where the f_name
column has an entry greater than 3. I assume I can use something similar to
m <- m[-grep("nchar(m$f_name)>3", m$f_name]
For those looking for a tidyverse approach, you can use dplyr::filter
:
m %>% dplyr::filter(nchar(f_name) > 3)
To reword your question slightly, you want to retain rows where entries in f_name have length of 3 or less. So how about:
subset(m, nchar(as.character(f_name)) <= 3)
Try this:
m[!nchar(as.character(m$f_name)) > 3, ]
The obligatory data.table
solution:
setDT(m)
m[ nchar(f_name) <= 3 ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With