Skip to content

Instantly share code, notes, and snippets.

@Hugoberry
Created March 9, 2017 16:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Hugoberry/8a13a69818c5fb3cb02c225708326cb1 to your computer and use it in GitHub Desktop.
Save Hugoberry/8a13a69818c5fb3cb02c225708326cb1 to your computer and use it in GitHub Desktop.
R Regex matching of mentions in twitts. with Power Query and R
let
Source = Csv.Document(File.Contents("RTwitterSample.csv"),[Delimiter=",", Columns=2, Encoding=1252, QuoteStyle=QuoteStyle.Csv]),
twitts = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
RScript = R.Execute("temp<-dataset#(lf)pattern<-""[#@]\\w+""#(lf)temp$mention<-sapply(temp$text,function(x) toString(regmatches(x, regexpr(pattern, x))))",[dataset=twitts ]),
out = RScript{[Name="temp"]}[Value]
in
out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment