Hi, I know I can do this with a for loop with strsplit and grep, but is
there more efficient way?

 

Given a data dataframe (input) and a category column (lst), 

 

> input

                                         item      loc

1 item 1.1: earnings <sep> item 1.2: w2 <sep>  shelf 1

2                        item 1.3: deductions drawer 1

3                          item 1.1: earnings  shelf 2

> lst

      item cat

1 item 1.1   A

2 item 1.2   B

3 item 1.3   C

 

how to get a result frame like 

 

> result

                                         item      loc cat

1 item 1.1: earnings <sep> item 1.2: w2 <sep>  shelf 1  AB

2                        item 1.3: deductions drawer 1   C

3                          item 1.1: earnings  shelf 2   A

 

Thanks,

Richard

 


        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
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.

Reply via email to