Home > front end >  generate list separate input character
generate list separate input character

Time:11-10

I have a table with a column name HS where data is like this:

HS <- c("44.01 44.12","44.1234","4561.10 4562.10 4620.1")

I would like to get a list :

listcodes = c("44.01","44.12","44.1234","4561.10","4562.10","4620.1")

CodePudding user response:

We can use strsplit and unlist

> unlist(strsplit(HS, " "))
[1] "44.01"   "44.12"   "44.1234" "4561.10" "4562.10" "4620.1" 

CodePudding user response:

We may use scan or strsplit

scan(text = paste(HS, collapse = " "), what = numeric(), quiet = TRUE)

If it should be character

scan(text = paste(HS, collapse = " "), what = "", quiet = TRUE)
[1] "44.01"   "44.12"   "44.1234" "4561.10" "4562.10" "4620.1" 
  •  Tags:  
  • r
  • Related