Re: [R] Mean of a row of a data frame

2018-03-20 Thread Richard M. Heiberger
rowMeans is designed for speed. It also has as.matrix inside it. On Tue, Mar 20, 2018 at 10:40 PM, Boris Steipe wrote: > R > rowMeans(roop) > [1] 1.67 5.33 3.00 > R > mean(as.numeric(roop[1,])) > [1] 1.67 > > > :-) > > > > >> On Mar 20, 2018, at 10:18

Re: [R] Mean of a row of a data frame

2018-03-20 Thread Richard M. Heiberger
> mean(list(1,4,0)) [1] NA Warning message: In mean.default(list(1, 4, 0)) : argument is not numeric or logical: returning NA > mean(unlist(roop[1,])) [1] 1.67 > apply(roop, 1, mean) [1] 1.67 5.33 3.00 data.frame is a list with some matrix characteristics. The list

Re: [R] Mean of a row of a data frame

2018-03-20 Thread Boris Steipe
R > rowMeans(roop) [1] 1.67 5.33 3.00 R > mean(as.numeric(roop[1,])) [1] 1.67 :-) > On Mar 20, 2018, at 10:18 PM, Sorkin, John wrote: > > I am trying to get the mean of a row of a data frame. My code follows: > > > roop <-

[R] Mean of a row of a data frame

2018-03-20 Thread Sorkin, John
I am trying to get the mean of a row of a data frame. My code follows: roop <- data.frame(x=c(1,2,3),y=c(4,5,2),z=c(0,9,4)) roop mean(roop[1,]) mean(roop[1,c("x","y","z")]) I get the following output: > roop x y z 1 1 4 0 2 2 5 9 3 3 2 4 > mean(roop[1,]) [1] NA Warning message: In