Using apply
s2 <- apply(x*x, 2, sum) s2
[1] 55 330 Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it.
On Tue, Oct 30, 2018 at 10:28 PM Steven Yen <styen at ntu.edu.tw> wrote:
I need help with "apply". Below, I have no problem getting the column sums.
1. How do I get the sum of squares?
2. In general, where do I look up these functions?
Thanks.
x<-matrix(1:10,nrow=5); x
sum <- apply(x,2,sum); sum
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.