I have a data frame where one column contains a string of numbers. Each row contains a set of numbers that vary in length. For example:
<code>Month Count
Jan "[1.2445, 23.888883, 16.11208347]"
Feb "[2.6473, 400.6256]"
March "[6723.1838282, 187.1212, 90.111, 75.1342899]"
</code>
<code>Month Count
Jan "[1.2445, 23.888883, 16.11208347]"
Feb "[2.6473, 400.6256]"
March "[6723.1838282, 187.1212, 90.111, 75.1342899]"
</code>
Month Count
Jan "[1.2445, 23.888883, 16.11208347]"
Feb "[2.6473, 400.6256]"
March "[6723.1838282, 187.1212, 90.111, 75.1342899]"
The goal is to convert the list into numeric format, and sum across each row. Resulting in something like (rounded decimals for ease):
<code>Month Count
Jan 41.245
Feb 403.2729
March 7075.500
</code>
<code>Month Count
Jan 41.245
Feb 403.2729
March 7075.500
</code>
Month Count
Jan 41.245
Feb 403.2729
March 7075.500
I have used this code which works for a single row, but I am unable to abstract it over the entire data frame by row.
<code>sum(as.numeric(strsplit(substr(Data$Count, 2, nchar(Data$Count) - 1), ',')[[1]]))
</code>
<code>sum(as.numeric(strsplit(substr(Data$Count, 2, nchar(Data$Count) - 1), ',')[[1]]))
</code>
sum(as.numeric(strsplit(substr(Data$Count, 2, nchar(Data$Count) - 1), ',')[[1]]))