[R] R help

Ulrik Stervbo ulrik.stervbo at gmail.com
Fri Aug 5 19:14:59 CEST 2016


I'm not quite sure if this is what you are looking for:

example.df <- data.frame(words= c("A T", "Z H", "B E", "C P H"), badwords =
c("A|I|J|H|K|L"))

# Extract the column with bad words
badwords <- example.df$badwords
badwords <- as.character(badwords[1])

# Subset the data.frame
subset(example.df, grepl(badwords, words))

As I understand your email the badwords column contains all bad words in
each cell, so I assume they are separated somehow. In my example I use |
because it used to signify OR in grep. Since all elements of the bad word
column are equal I just get the first element, make sure it is a character,
and use grepl to subset the entire data.frame

HTH
Ulrik

On Fri, 5 Aug 2016 at 17:19 <ruipbarradas at sapo.pt> wrote:

> Hello,
>
> Please use ?dput to post a data example. Use something like the
> following, where 'dat' is the name of your data.frame.
>
> dput(head(dat, 30))  # paste the output of this in a mail
>
> Hope this helps,
>
> Rui Barradas
>
>
> Citando Вова Грабарник <v.grabarnik at gmail.com>:
>
> > Dear R command,
> >
> > I was wondering if I could ask you recommendations on my problem if that
> is
> > fine with you.
> > Basically, I have a data frame with 5 columns and 10 000 tweets
> > recorded(rows). Those columns are: numberofatweet(number), tweet (actual
> > textual tweet), locations(from where tweet sent), badwords(words that
> > should not be used on twitter, that is just a column irrespective the
> > number of a tweet and it contains only 80 rows with one word recorded in
> > one cell.
> > My question is whether it is possible to select only the rows which would
> > contain such tweets, where in column "tweet"(actual text) there was one
> of
> > those words from badwords column present. I tried to use grep and grepl,
> > but nothing seems to be working.
> >
> > Thank you in advance,
> > Vladimir
> >
> >         [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.htmland provide commented,
> > minimal, self-contained, reproducible code.
>
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

	[[alternative HTML version deleted]]



More information about the R-help mailing list