Turning a string of numbers into a list of numbers in R

后端 未结 4 489
渐次进展
渐次进展 2021-01-21 05:09

Apologies if this question is too easy, I know how to do it in Python but I currently need it in R.

As part of an SQL query I get a variable with some numbers (the lengt

4条回答
  •  时光说笑
    2021-01-21 05:41

    You can try using gsub to first replace { and } and then split in vector using strsplit. Finally, convert it to numeric as:

    x <- "{0.5,0.25,0.75,0.5}" 
    as.numeric(strsplit(gsub("[{}]","",x), split = ",")[[1]])
    #[1] 0.50 0.25 0.75 0.50
    

提交回复
热议问题