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 character vector. I'd really like to convert them to numeric (and if possible sum them up right away). E.g. one of my cells might look like
6 310 21 20 64
I've tried
Reduce(sum,L)
and
as.numeric(L)
but I always get Warning message:
NAs introduced by coercion
Here, L is just a sample object I created to put one of my cells into.
sum(as.numeric(strsplit("6 310 21 20 64",' ')[[1]]))
. You might have to modify the code a bit to apply it to all of your data. Postdput
of your data if you need further help. – etiennesapply(strsplit(str1,' '), function(x) sum(type.convert(x)))
– David Arenburgtype.convert
– etienne