Consider this code
lapply(lst,rowSums)
lst
is a list of five data frames. Each data frame has, for example, four columns and ten rows. I want to add the values of the columns in each row, however, I do not want to include the value of column one in the sum.
I can use a for
loop and the code below:
lst_sum = list()
for (ii in c(1,5))
{
dummy <- lst[[ii]]
dummy <- rowSums(dummy[,seq(2,4,by = 1)])
lst_sum[[ii]] = dummy
}
I would like to use lapply
or a similar function because I think the for
loops looks ugly and inefficient.