TobKel
TobKel

Reputation: 1453

R Extract name of dataframe and mutate new column

I have a dataframe of t.tests with 2 columns: objects and their p.value:

`t.test>1sd` <- tibble( 
object = c('obj1','obj2','obj3'),
p.value= c(0.45,0.34,0.02)
)

> `t.test>1sd`
# A tibble: 3 x 2
object p.value
<chr>    <dbl>
1 obj1      0.45
2 obj2      0.34
3 obj3      0.02

And now I want to add a third column. The values in the new column should contain a part of the name of the dataframe. From the datraframe-name t.test>1sd i want to extract >1sd . (In this case >1sd is a special boundary) But I have more dataframes with different boundaries (>2sd, >3sd,...) So I need a solution that separates t.test and >1sd

Here is my desired output:

> `t.test>1sd`
# A tibble: 3 x 2
object p.value    boundary
<chr>    <dbl>      <chr> 
1 obj1      0.45    >1sd
2 obj2      0.34    >1sd
3 obj3      0.02    >1sd

Is there a solution in the stringr-package? Can someone help me?

Upvotes: 0

Views: 122

Answers (1)

ha-pu
ha-pu

Reputation: 581

Based on the suggestion by LAP str_extract('t.test>1sd', '\\>[:digit:]{1}sd') should do the trick.

Upvotes: 1

Related Questions