简体   繁体   中英

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?

根据LAP的建议, str_extract('t.test>1sd', '\\\\>[:digit:]{1}sd')应该可以解决问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM