string - R: get dataframe row with specific characters -




i need detect rows of df/tibble containing specific sequence of characters.

seq <- "rt @aventussystems" sequence

df <- structure(list(text = c("@aventussystems wow, upgrade of investor",  "rt @aventussystems: recent article our investors shown in forbes! t.co/n8ogwiedpu #aventus #globaladvisors #4thefans #ti…",  "@aventussystems nice have project", "rt @aventussystems: join #ticketrevolution #aventus today! #aventus #ticketrevolution #aventcoin #4thefans t.co/oplycfmw4a" ), tweet_id = c("898359464444559360", "898359342952439809", "898359326552633345",  "898359268226736128"), created_at = structure(c(17396, 17396,  17396, 17396), class = "date")), .names = c("text", "tweet_id",  "created_at"), row.names = c(na, -4l), class = c("tbl_df", "tbl",  "data.frame"))  select(df, contains(seq)) # tibble: 4 x 0 

sapply(df$text, grepl, seq) return 4 false

what wrong? correct solution? thank help

first, grepl vectorized on argument x, don't need sapply. grepl(seq, df$text).

why code doesn't work sapply passes each element of x argument function in fun argument first argument (so looking search pattern "@aventussystems wow, upgrade of investor", etc. in seq object.

lastly, dplyr::select selects columns, whereas want use dplyr::filter, filters rows.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -