R: convert list of numbers from character to numeric

前端 未结 3 1021
旧巷少年郎
旧巷少年郎 2021-01-24 22:17

I have a column in my dataframe where in every cell there are one or more numbers. If there are many numbers, they are seperated with a space. Furthermore, R considers them as a

3条回答
  •  一个人的身影
    2021-01-24 22:59

    We can use scan

    sum(scan(text=str1, what=numeric(), quiet=TRUE))
    #[1] 421
    

    data

    str1 <- "6 310 21 20 64"
    

提交回复
热议问题