Here is an attempt. If you need a second data frame, first use df2 <- df1so that you have the old and the new ( df2will be old), or wrap it with as.data.frame()and name it df2.
df1[] <- lapply(df1, function(x) {
s <- strsplit(as.character(x), "|", fixed = TRUE)
vapply(s, function(a) sum(as.numeric(a)), 1)
})
which gives
df1
, . . , , .
1: strsplit() scan() .
df1[] <- lapply(df1, function(x) {
vapply(as.character(x), function(a) sum(scan(text = a, sep = "|")), 1)
})
2: , . , df1.
rs <- rowSums(read.table(text = as.matrix(df1), sep = "|"))
dim(rs) <- dim(df1)
dimnames(rs) <- dimnames(df1)
as.data.frame(rs)
, ...
as.data.frame(
`dimnames<-`(
`dim<-`(
rowSums(read.table(text = as.matrix(df1), sep = "|")),
dim(df1)
),
dimnames(df1)
)
)