0

I want to calculate mean and sd from column in dataframe. This column contain NA, and Inf value.

This is some example of value in this column

value

0.9343113   

0.8339523


0.0000000


NaN

Inf

I try to use apply function but it give an error message

mean=apply(am_bp$foldchange_so,2,FUN=function(x){mean(x,na.rm=T)})

Error in apply(am_bp$foldchange_so, 2, FUN = function(x) { : dim(X) must have a positive length

Then I try mean=colMeans(matrix(am_bp$foldchange_so),na.rm=TRUE) but it give inf value

Moreover, I don't know how to calculate sd in the column

How should I solve this problem

Vayami
  • 11
  • 3
  • 2
    What is the meaning of infinity in this case? You may want to look at `is.finite` but it's possible that infinity is the "correct" answer here. – Hugh Aug 13 '13 at 05:25
  • 3
    why are you using `apply` or `colMeans` on a vector? Why not simply `mean(am_bp$foldchange_so, na.rm = TRUE)`? – mnel Aug 13 '13 at 05:32
  • There was recently a long discussion about `colSD` (http://stackoverflow.com/questions/17549762/is-there-such-colsd-in-r), but it really doesn't look like you need it here. – Thomas Aug 13 '13 at 05:52
  • 1
    It looks like you're new to `R`, so please take some time to study the R-intro manual and some of the online tutorials. It'll save you a lot of pain. – Carl Witthoft Aug 13 '13 at 12:00
  • I already use mean(am_bp$foldchange_so, na.rm = TRUE) but it also give inf value which is not the answer I want – Vayami Aug 14 '13 at 03:29

0 Answers0