I would replace "," with "." Using sub . ( read.table/read.csv also has a dec parameter). Using cSplit from splitstackshape , split the columns into two, specifying sep as splitstackshape The output will be data.table . Create the Total column using rowSums . If you want to return NA for strings, all NAs , this is possible (one of the options shown in the second solution)
df$colname <- sub(',', '.', df$colname) library(splitstackshape) dt <- cSplit(df, 'colname', '+') dt[, Total:=rowSums(.SD,na.rm=TRUE)][]
Or using base R , split the column ("colname") with strsplit . The result will be a list. Convert "character" to "numeric", pad NAs to get the same length in all list items and rbind ( df2 <- do.call(...,) ). Create the “Total” column on rowSums , change the item to NA for those NAs in both columns.
lst <- lapply(strsplit(df$colname, '[+]'), as.numeric) df2 <- do.call(rbind.data.frame, lapply(lst, `length<-`, max(sapply(lst, length)))) names(df2) <- paste0('colname', 1:2) df2$Total <- (NA^!rowSums(!is.na(df2)))*rowSums(df2, na.rm=TRUE) df2
Or in this case, you can also use eval(parse( , which avoids changing the value 0 to NA
df2$Total <- unname(sapply(df$colname, function(x) eval(parse(text=x))))
Update
If you need to replace NA with 0 with "colname2"
df2$colname2[with(df2, is.na(colname2) & !is.na(colname1))] <- 0 df2
data
df <- structure(list(colname = structure(c(4L, 1L, NA, 5L, 3L, 2L, 6L), .Label = c("55", "56,5", "56,5 +0.50", "57 +0.10", "57,5 +2.00", "58"), class = "factor")), .Names = "colname", row.names = c(NA, -7L), class = "data.frame")