I need to sum every two columns
for example
x1 x2 x3 x4
12 2 3 7
1 4 6 5
I need
X1 X2
14 10
5 11
I tried apply function
and I tried this function
mat is a matrix
mat1=matrix()
for(i in 1:nrow(mat)){
for(j in 1:ncol(mat)){
mat1[i,j]=mat[j,i]+mat[j,i+1]
}}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…