Hello everyone, i'd like to manage some character vector data inside a df and i have no idea

Viewed 24

#I have something like this

col1 <- c('A','B','C')

col2 <- c('[0.0,1.0]','[2.0,3.0,4.0]','[5.0]') #as.character

col3 <- c('[200.5,300.5]','[400.5,500.5,600.5]','[700.5]') #as.character

df <- data.frame(col1,col2,col3)

#I'd love to remove those brackets and transform col2 and col3 into numeric

col2_A <- as.numeric(c(0.0,1.0))

col3_A <- as.numeric(c(200.5,300.5))

col2_B <- as.numeric(c(2.0,3.0,4.0))

col3_B <- as.numeric(c(400.5,500.5,600.5))

col2_C <- as.numeric(c(5.0))

col3_C <- as.numeric(c(700.5))

#I'd also love to have something like that

df_A <- data.frame(col2_A,col3_A)

df_B <- data.frame(col2_B,col3_B)

df_C <- data.frame(col2_C,col3_C)

#I'm pretty sure that exists some intelligent way of doing it

#Any help?

#Thanks in advance

0 Answers
Related