[R] Problem with Median

Petr PIKAL petr.pikal at precheza.cz
Wed May 9 08:40:04 CEST 2012


Hi

> 
> 
> I might be silly but if I was going to type in dput() then how should I 
> send the data over here? 

> dput(zdrz20)

outputs tou your console

structure(list(sklon = c(95, 95, 40, 40, 40, 40, 20, 20, 20, 
20, 20, 20, 20), ot = c(15, 4, 10, 15, 4, 1.5, 1.5, 4, 10, 15, 
4, 10, 15), doba = c(5.883333333, 15.75, 12.5, 9.166666667, 27, 
65.16666667, 88, 38.25, 17.33333333, 12.5, 38.2, 17.3, 12.5)), .Names = 
c("sklon", 
"ot", "doba"), row.names = c(NA, 13L), class = "data.frame")

you can copy it to your mail and anybody can just paste this and assign it 
to an object.

a.AC <- subset(data, class == "A-C", select = a)
This result probably in data frame (you can check by str(a.AC)) and as 
such you can not put it directly to median function.

Regards
Petr


> Instead, I've just uploaded the image online, you can access it via the 
link below.
> http://i1165.photobucket.com/albums/q585/halfpirate/data.jpg 
> 
> > Date: Mon, 7 May 2012 14:55:24 -0400
> > Subject: Re: [R] Problem with Median
> > From: sarah.goslee at gmail.com
> > To: bell_beauty12 at hotmail.com
> > CC: r-help at r-project.org
> > 
> > Please use dput() to give us your data (eg dput(data) ) rather than
> > simply pasting it in.
> > 
> > Sarah
> > 
> > On Mon, May 7, 2012 at 2:52 PM, Suhaila Haji Mohd Hussin
> > <bell_beauty12 at hotmail.com> wrote:
> > >
> > > Hello.
> > > I'm trying to compute median for a filtered column based on other 
> column but there was something wrong. I'll show how I did step by step.
> > > Here's the data:
> > >     a     b     c      class
> > >
> > > 1   12   0      90     A-B2   3     97    11     A-B3   78   NA 123
> A-C4   NA   NA    12    A-C5   8     33     2     A-B6   12   NA     0  
A-D
> > > On the command I typed:
> > > 1) data = read.csv("data.csv")
> > >
> > > 2) a.AC <- subset(data, class == "A-C", select = a)
> > > 3) median(a.AC)Error in median.default(a.AC) : need numeric data
> > > 4) is.numeric(a.AC)FALSE
> > > 5) as.numeric(a.AC)Error: (list) object cannot be coerced to type 
'double'
> > > How can I fix this? Please help.
> > > Cheers,Suhaila
> > 
> > 
> > -- 
> > Sarah Goslee
> > http://www.functionaldiversity.org
>                       ______________________________________________
> R-help at r-project.org mailing list
> 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