Alexi Zubiria
2004-Jun-24 20:23 UTC
[R] The "median" function in R does not work properly.
Hi, 1.) The "median" function does not work well. Please refer to the data below (same data is attached as txt-delimited). This is what I try to do in R: median ( dataf [2:9] ) I get warning: "needs numeric data" 2.) BUT if apply the median to a single vector: median ( dataf [,2]] ) then it works: 3.) How come the "median" function does not let me take the median of all 8 vectors at once? Obviously, if I can perform the test on a single array, then it means I have numeric data because I do not get warning. Also, if I look at the "mode" for each array I get "numeric". Probe 1 256 589 308 698 745 850 750 1200 Probe 2 225 422 350 625 400 650 852 1400 Probe 3 295 530 325 585 350 700 752 1100 Probe 4 300 450 425 430 700 645 735 1250 Thanks in advance, Alexi Zubiria Technical Support Specialist Silicon Genetics 2601 Spring Street Redwood City CA, 94063 Main: 650-367-9600 Support: 866-744-7638 alexi@silicongenetics.com [[alternative HTML version deleted]]
Duncan Murdoch
2004-Jun-24 20:30 UTC
[R] The "median" function in R does not work properly.
On Thu, 24 Jun 2004 13:23:22 -0700, "Alexi Zubiria" <alexi at silicongenetics.com> wrote :>Hi, > > > >1.) The "median" function does not work well.It works fine for me. You were trying to take the median of a list. It only knows how to take the median of a vector. Use dataf [,2:9] not dataf [2:9] to get a vector. Duncan Murdoch
Duncan Murdoch
2004-Jun-24 20:34 UTC
[R] The "median" function in R does not work properly.
Oops, missed something below: On Thu, 24 Jun 2004 13:23:22 -0700, "Alexi Zubiria" <alexi at silicongenetics.com> wrote :>Hi, > > > >1.) The "median" function does not work well.It works fine for me. You were trying to take the median of a list. It only knows how to take the median of a vector of numbers. Use as.matrix(dataf [,2:9]) not dataf [2:9] to get a numeric matrix (which is a vector of numbers). Duncan Murdoch
Sundar Dorai-Raj
2004-Jun-24 20:38 UTC
[R] The "median" function in R does not work properly.
Alexi Zubiria wrote:> Hi, > > > > 1.) The "median" function does not work well. Please refer to the data > below (same data is attached as txt-delimited). This is what I try to > do in R: > > > > median ( dataf [2:9] ) > > > > I get warning: "needs numeric data" > > > > 2.) BUT if apply the median to a single vector: > > > > median ( dataf [,2]] ) > > > > then it works: > > > > > > 3.) How come the "median" function does not let me take the median of > all 8 vectors at once? Obviously, if I can perform the test on a single > array, then it means I have numeric data because I do not get warning. > Also, if I look at the "mode" for each array I get "numeric". > > > >median *does* work properly and as documented: Arguments: x: a numeric vector containing the values whose median is to be computed. so you supplied a `list' or `data.frame' not a vector. I'm not sure what you expected, but if you want to obtain the median of each column in your matrix, then use ?apply: apply(as.matrix(dataf), 2, median) Or if you want to get the median of all vectors (a single number) then use median(as.matrix(dataf)) I assume from your post you supplied a data.frame, however if dataf really is a matrix (try data.class(dataf)) then median(dataf) will accomplish the last line (at least on R-1.9.1 for win2000). --sundar