r - Split data frame column when square brackets -


i have data frame model estimations. depending on observation estimation has value or value confidence interval between square brackets. way, variable character (i guess need change some-when)

df<-data.frame(c("5","3","8 [3 - 5]") 

i split data frame column (x) 2 columns. first 1 estimated values (y) , second 1 confidence interval or without brackets (z).

i have tried tidyr::separate , tidyr::split (i big fun of dplyr family:-), not wished result.

tidyr::separate(col=x,into=c("y","z"),sep="//[") 

do know doing wrong?

this can done extract

library(tidyr) extract(df, x, = c("y", "z"), "(\\d+)\\s*(.*)") 

or use extra argument in separate

separate(df, x, = c("y", "z"), "\\s+", = "merge") 

data

df <- data.frame(x= c("5","3","8 [3 - 5]")) 

Comments

Popular posts from this blog

'hasOwnProperty' in javascript -

python - ValueError: No axis named 1 for object type <class 'pandas.core.series.Series'> -

java - How to provide dependency injections in Eclipse RCP 3.x? -