Saturday, November 19, 2016

Grep Strs in R

Identify specific characters in columns
> data[1:20,]
       series   network      Type X..Eps Air.Day National.Time     daypart Run_time..min.  Unique.HHs Total.Hrs.Viewed
...
14  series314  network5 Broadcast      1       T       8:00 PM       prime             60    991,953          469,083
15  series838  network4 Broadcast      4       T       9:00 PM       prime             60  2,636,448        1,534,543
16  series230  network5 Broadcast      3       M      10:01 PM       prime             59  2,080,862        1,112,973
17   series39  network4 Broadcast      3       U       7:00 PM primeaccess             60  2,133,072        1,123,172
18  series193  network5 Broadcast      5     T U      10:01 PM       prime             59  3,351,520        1,795,463
# Air Day - Day of episode airing (M, T, W, R, F, S, U)
> unlist(lapply(data$Air.Day, function(x) grepl('M',x)))
   [1]  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
...

Fetch out specific strings
  tmp=str_replace_all(topstr, " ", "_")
  tmp=paste("^",tmp,"$", sep="")
  tmp2=grep(tmp, totalSampleName)

No comments:

Post a Comment

Blog Archive