[R] Text search

Ashta @ew@@hm @end|ng |rom gm@||@com
Sun Jan 26 00:22:06 CET 2020


Hi all,
>From  one of the columns of the data frame I want to search and
extract  a text that contains Tall or   Short  and create new column
that should contain these texts in a corresponding row.
My example data and the desired output are shown below

dat<-read.table(text="obs Year char
1  2001 Tall156
2  2002 12565Tall
3  2003 all54
4  2004 Short
5  2005 54all
6  2006 7Short12 ",header=TRUE,stringsAsFactors=F)
dat$new <- "      "

Desired out put
obs Year     char        new
   1 2001   Tall156      Tall
   2 2002 12565Tall    Tall
   3 2003     all54
   5 2004     Short      Short
   6 2005     Shall54
   7 2006  7Short12   Short

How do I get my desired output?
Thank you.



More information about the R-help mailing list