[R] simple question - mean of a row of a data.frame

Kehl Dániel kehld at ktk.pte.hu
Thu Feb 12 00:21:42 CET 2015


Hi,

rock[2,] is a data frame and you should not use sum() on a data frame, first google hit for the error message gives

http://stackoverflow.com/questions/19697498/r-beginner-argument-is-not-numeric-or-logical-returning-na

Otherwise I think you should use

?rowSums and ?rowMeans if you have numeric data frames.

HTH,
daniel
________________________________________
Feladó: R-help [r-help-bounces at r-project.org] ; meghatalmazó: Matthew Keller [mckellercran at gmail.com]
Küldve: 2015. február 11. 23:49
To: r help
Tárgy: [R] simple question - mean of a row of a data.frame

Hi all,

Simple question I should know: I'm unclear on the logic of why the sum of a
row of a data.frame returns a valid sum but the mean of a row of a
data.frame returns NA:

sum(rock[2,])
[1] 10901.05

mean(rock[2,],trim=0)
[1] NA
Warning message:
In mean.default(rock[2, ], trim = 0) :
  argument is not numeric or logical: returning NA

I get that rock[2,] is itself a data.frame of mode list, but why the
inconsistency between functions? How can you figure this out from, e.g.,
?mean
?sum

Thanks in advance,

Matt


--
Matthew C Keller
Asst. Professor of Psychology
University of Colorado at Boulder
www.matthewckeller.com

        [[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.



More information about the R-help mailing list