Quantcast

Problem with Median

classic Classic list List threaded Threaded
20 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Problem with Median

Suhaila Haji Mohd Hussin

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    
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Problem with Median

Sarah Goslee
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
<[hidden email]> 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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Problem with Median

Suhaila Haji Mohd Hussin

I might be silly but if I was going to type in dput() then how should I send the data over here?
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: [hidden email]
> To: [hidden email]
> CC: [hidden email]
>
> 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
> <[hidden email]> 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
     
______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Problem with Median

Suhaila Haji Mohd Hussin
In reply to this post by Suhaila Haji Mohd Hussin

Thank you so much!
Suhaila.

> Date: Mon, 7 May 2012 15:08:47 -0400
> Subject: Re: [R] Problem with Median
> From: [hidden email]
> To: [hidden email]
>
> Your problem is that a.AC is a dataframe:
>
>
> > x <- read.table(text = "   a     b     c      class
> + 1   12   0      90     A-B
> + 2   3     97    11     A-B
> + 3   78   NA    123   A-C
> + 4   NA   NA    12    A-C
> + 5   8     33     2     A-B
> + 6   12   NA     0     A-D", header = TRUE)
> > a.AC <- subset(x, class == "A-C", select = a)
> > # same error
> > median(a.AC)
> Error in median.default(a.AC) : need numeric data
>
> > # now look a the structure of a.AC (its a dataframe)
> > str(a.AC)
> 'data.frame':   2 obs. of  1 variable:
>  $ a: int  78 NA
> > # now do it right
> > median(a.AC$a)
> [1] NA
> > median(a.AC$a, na.rm = TRUE)
> [1] 78
>
>
>
> On Mon, May 7, 2012 at 2:52 PM, Suhaila Haji Mohd Hussin
> <[hidden email]> 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
> >        [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] 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.
>
>
>
> --
> Jim Holtman
> Data Munger Guru
>
> What is the problem that you are trying to solve?
> Tell me what you want to do, not how you want to do it.
     
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Problem with Median

Duncan Murdoch-2
In reply to this post by Suhaila Haji Mohd Hussin
On 07/05/2012 3:05 PM, Suhaila Haji Mohd Hussin wrote:
> I might be silly but if I was going to type in dput() then how should I send the data over here?

Cut and paste.  For example,  if I have a dataframe named x and type
dput(x), I see

structure(list(a = 1:10), .Names = "a", row.names = c(NA, -10L
), class = "data.frame")

If you run

x <- structure(list(a = 1:10), .Names = "a", row.names = c(NA, -10L
), class = "data.frame")

you'll get a dataframe that looks just like mine.  Then you can start to
answer questions about it.

I can't do anything with your jpeg to answer your questions about your
dataframe.

Duncan Murdoch

> 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: [hidden email]
> >  To: [hidden email]
> >  CC: [hidden email]
> >
> >  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
> >  <[hidden email]>  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
>    
>
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Problem with Median

Suhaila Haji Mohd Hussin
In reply to this post by Suhaila Haji Mohd Hussin







Hello.
Now the median is solved but then I'm still figuring out how to put the updated column back to replace the original column of the whole data. I'll show you what I meant:
Continuing from the previous commands you guys helped out I continued as followed:
Original Data: http://i1165.photobucket.com/albums/q585/halfpirate/data.jpg

Before column a: http://i1165.photobucket.com/albums/q585/halfpirate/1.jpg

1) a.AC [is.na(a.AC)] <- median(a.AC$a, na.rm= TRUE)
2) a.ACAfter column a: http://i1165.photobucket.com/albums/q585/halfpirate/2.jpg
3) data$a <- a.ACGives me error that the original data has 6 rows yet the one I'm replacing is 1 row.
I understand the error and I don't want to completely replace the column if I really want to. Basically I'm expecting the result to be like this. After you compare the original data, the final answer should be like this http://i1165.photobucket.com/albums/q585/halfpirate/3.jpg
Please help.Suhaila
From: [hidden email]
To: [hidden email]
CC: [hidden email]
Subject: RE: [R] Problem with Median
Date: Tue, 8 May 2012 07:22:19 +1200





Thank you so much!
Suhaila.

> Date: Mon, 7 May 2012 15:08:47 -0400
> Subject: Re: [R] Problem with Median
> From: [hidden email]
> To: [hidden email]
>
> Your problem is that a.AC is a dataframe:
>
>
> > x <- read.table(text = "   a     b     c      class
> + 1   12   0      90     A-B
> + 2   3     97    11     A-B
> + 3   78   NA    123   A-C
> + 4   NA   NA    12    A-C
> + 5   8     33     2     A-B
> + 6   12   NA     0     A-D", header = TRUE)
> > a.AC <- subset(x, class == "A-C", select = a)
> > # same error
> > median(a.AC)
> Error in median.default(a.AC) : need numeric data
>
> > # now look a the structure of a.AC (its a dataframe)
> > str(a.AC)
> 'data.frame':   2 obs. of  1 variable:
>  $ a: int  78 NA
> > # now do it right
> > median(a.AC$a)
> [1] NA
> > median(a.AC$a, na.rm = TRUE)
> [1] 78
>
>
>
> On Mon, May 7, 2012 at 2:52 PM, Suhaila Haji Mohd Hussin
> <[hidden email]> 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
> >        [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] 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.
>
>
>
> --
> Jim Holtman
> Data Munger Guru
>
> What is the problem that you are trying to solve?
> Tell me what you want to do, not how you want to do it.


I might be silly but if I was going to type in dput() then how should I send the data over here?
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: [hidden email]
> To: [hidden email]
> CC: [hidden email]
>
> 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
> <[hidden email]> 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     

     
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Problem with Median

David Winsemius

On May 7, 2012, at 5:16 PM, Suhaila Haji Mohd Hussin wrote:

>
> Hello.
> Now the median is solved but then I'm still figuring out how to put  
> the updated column back to replace the original column of the whole  
> data. I'll show you what I meant:
> Continuing from the previous commands you guys helped out I  
> continued as followed:
> Original Data: http://i1165.photobucket.com/albums/q585/halfpirate/data.jpg
>
> Before column a: http://i1165.photobucket.com/albums/q585/halfpirate/1.jpg

That fine for sending pictures to the family but NOT for communicating  
R code.
>
> 1) a.AC [is.na(a.AC)] <- median(a.AC$a, na.rm= TRUE)
> 2) a.ACAfter column a: http://i1165.photobucket.com/albums/q585/halfpirate/2.jpg
> 3) data$a <- a.ACGives me error that the original data has 6 rows  
> yet the one I'm replacing is 1 row.
> I understand the error and I don't want to completely replace the  
> column if I really want to.

You were not attempting to replace the entire  column, but you were  
trying to replace 6 entries. So why not... :

a.AC [is.na(a.AC)] <- rep( median(a.AC$a, na.rm= TRUE) , 6)


> Basically I'm expecting the result to be like this. After you  
> compare the original data, the final answer should be like this http://i1165.photobucket.com/albums/q585/halfpirate/3.jpg

What part of "I can't do anything with your jpeg to answer your  
questions about your dataframe" was difficult to understand? We do NOT  
want pictures from which we need to repeat data entry that you have  
already done.  The first virtue of a programmer being laziness.  
Console output is also very ambiguous.  Learn to use str() and dput()  
or dump().

?dput
?dump

And run the examples. please.

--
David.


> Please help.Suhaila
> From: [hidden email]
> To: [hidden email]
> CC: [hidden email]
> Subject: RE: [R] Problem with Median
> Date: Tue, 8 May 2012 07:22:19 +1200
>
> Thank you so much!
> Suhaila.
>
>> Date: Mon, 7 May 2012 15:08:47 -0400
>> Subject: Re: [R] Problem with Median
>> From: [hidden email]
>> To: [hidden email]
>>
>> Your problem is that a.AC is a dataframe:
>>
>>
>>> x <- read.table(text = "   a     b     c      class
>> + 1   12   0      90     A-B
>> + 2   3     97    11     A-B
>> + 3   78   NA    123   A-C
>> + 4   NA   NA    12    A-C
>> + 5   8     33     2     A-B
>> + 6   12   NA     0     A-D", header = TRUE)
>>> a.AC <- subset(x, class == "A-C", select = a)
>>> # same error
>>> median(a.AC)
>> Error in median.default(a.AC) : need numeric data
>>
>>> # now look a the structure of a.AC (its a dataframe)
>>> str(a.AC)
>> 'data.frame':   2 obs. of  1 variable:
>> $ a: int  78 NA
>>> # now do it right
>>> median(a.AC$a)
>> [1] NA
>>> median(a.AC$a, na.rm = TRUE)
>> [1] 78
>>
>>
>>
>> On Mon, May 7, 2012 at 2:52 PM, Suhaila Haji Mohd Hussin
>> <[hidden email]> 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
>>>       [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> [hidden email] 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.
>>
>>
>>
>> --
>> Jim Holtman
>> Data Munger Guru
>>
>> What is the problem that you are trying to solve?
>> Tell me what you want to do, not how you want to do it.
>
>
> I might be silly but if I was going to type in dput() then how  
> should I send the data over here?
> 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: [hidden email]
>> To: [hidden email]
>> CC: [hidden email]
>>
>> 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
>> <[hidden email]> 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   
>
>  
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.

David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Problem with Median

Suhaila Haji Mohd Hussin

Hello.
Sorry if that's considered laziness as I've just learnt R and didn't know how important it is to do dput for all problems.
If I was truly lazy then I wouldn't even bother to sign up here and ask questions.
Please be nicer next time.
Suhaila.
> CC: [hidden email]
> From: [hidden email]
> To: [hidden email]
> Subject: Re: [R] Problem with Median

> Date: Mon, 7 May 2012 20:25:24 -0400
>
>
> On May 7, 2012, at 5:16 PM, Suhaila Haji Mohd Hussin wrote:
>
> >
> > Hello.
> > Now the median is solved but then I'm still figuring out how to put  
> > the updated column back to replace the original column of the whole  
> > data. I'll show you what I meant:
> > Continuing from the previous commands you guys helped out I  
> > continued as followed:
> > Original Data: http://i1165.photobucket.com/albums/q585/halfpirate/data.jpg
> >
> > Before column a: http://i1165.photobucket.com/albums/q585/halfpirate/1.jpg
>
> That fine for sending pictures to the family but NOT for communicating  
> R code.
> >
> > 1) a.AC [is.na(a.AC)] <- median(a.AC$a, na.rm= TRUE)
> > 2) a.ACAfter column a: http://i1165.photobucket.com/albums/q585/halfpirate/2.jpg
> > 3) data$a <- a.ACGives me error that the original data has 6 rows  
> > yet the one I'm replacing is 1 row.
> > I understand the error and I don't want to completely replace the  
> > column if I really want to.
>
> You were not attempting to replace the entire  column, but you were  
> trying to replace 6 entries. So why not... :
>
> a.AC [is.na(a.AC)] <- rep( median(a.AC$a, na.rm= TRUE) , 6)
>
>
> > Basically I'm expecting the result to be like this. After you  
> > compare the original data, the final answer should be like this http://i1165.photobucket.com/albums/q585/halfpirate/3.jpg
>
> What part of "I can't do anything with your jpeg to answer your  
> questions about your dataframe" was difficult to understand? We do NOT  
> want pictures from which we need to repeat data entry that you have  
> already done.  The first virtue of a programmer being laziness.  
> Console output is also very ambiguous.  Learn to use str() and dput()  
> or dump().
>
> ?dput
> ?dump
>
> And run the examples. please.
>
> --
> David.
>
>
> > Please help.Suhaila
> > From: [hidden email]
> > To: [hidden email]
> > CC: [hidden email]
> > Subject: RE: [R] Problem with Median
> > Date: Tue, 8 May 2012 07:22:19 +1200
> >
> > Thank you so much!
> > Suhaila.
> >
> >> Date: Mon, 7 May 2012 15:08:47 -0400
> >> Subject: Re: [R] Problem with Median
> >> From: [hidden email]
> >> To: [hidden email]
> >>
> >> Your problem is that a.AC is a dataframe:
> >>
> >>
> >>> x <- read.table(text = "   a     b     c      class
> >> + 1   12   0      90     A-B
> >> + 2   3     97    11     A-B
> >> + 3   78   NA    123   A-C
> >> + 4   NA   NA    12    A-C
> >> + 5   8     33     2     A-B
> >> + 6   12   NA     0     A-D", header = TRUE)
> >>> a.AC <- subset(x, class == "A-C", select = a)
> >>> # same error
> >>> median(a.AC)
> >> Error in median.default(a.AC) : need numeric data
> >>
> >>> # now look a the structure of a.AC (its a dataframe)
> >>> str(a.AC)
> >> 'data.frame':   2 obs. of  1 variable:
> >> $ a: int  78 NA
> >>> # now do it right
> >>> median(a.AC$a)
> >> [1] NA
> >>> median(a.AC$a, na.rm = TRUE)
> >> [1] 78
> >>
> >>
> >>
> >> On Mon, May 7, 2012 at 2:52 PM, Suhaila Haji Mohd Hussin
> >> <[hidden email]> 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
> >>>       [[alternative HTML version deleted]]
> >>>
> >>> ______________________________________________
> >>> [hidden email] 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.
> >>
> >>
> >>
> >> --
> >> Jim Holtman
> >> Data Munger Guru
> >>
> >> What is the problem that you are trying to solve?
> >> Tell me what you want to do, not how you want to do it.
> >
> >
> > I might be silly but if I was going to type in dput() then how  
> > should I send the data over here?
> > 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: [hidden email]
> >> To: [hidden email]
> >> CC: [hidden email]
> >>
> >> 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
> >> <[hidden email]> 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   
> >
> >  
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] 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.
>
> David Winsemius, MD
> West Hartford, CT
>
     
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Problem with Median

Suhaila Haji Mohd Hussin





Hello.
Thanks for the help and your reasonable explanation. I'll definitely start using 'dput' next time.
Apologies for the trouble to all who helped me.
Suhaila.

> On 05/08/2012 06:35 PM, Suhaila Haji Mohd Hussin wrote:
> >
> > Hello.
> > Sorry if that's considered laziness as I've just learnt R and didn't know how important it is to do dput for all problems.
> > If I was truly lazy then I wouldn't even bother to sign up here and ask questions.
> > Please be nicer next time.
>
> Hi Suhaila,
> It looks like you are confused about indexing your data frame. You want
> to replace the NA value in the fourth row and first column of your data
> frame with a median. Say that your median value really is 78. What you
> want to do is one of these:
>
> median_a.AC<-median(unlist(a.AC),na.rm=TRUE)
> x[4,1]<-median_a.AC
> x$a[4]<-median_a.AC
> x[4,"a"]<-median_a.AC
>
> which are all pretty much equivalent. The operation of selecting one or
> more values from a data frame is known as "extraction" in R. The way you
> have defined a.AC results in a "list" object. If you "unlist" it, it
> becomes a vector with two elements, 78 and NA. If you want the median,
> you will have to use the na.rm=TRUE argument or you will get NA. Now
> that you have the median, you can change the value of the NA element to
> that median using one of the above commands.
>
> The reason that everyone was cross about sending pictures of data is
> that it forces anyone who wants to help you to type in the data
> manually. The "dput" function makes it easy on the helpers.
>
> Jim
     
     
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Problem with Median

David Winsemius
In reply to this post by Suhaila Haji Mohd Hussin

On May 8, 2012, at 4:35 AM, Suhaila Haji Mohd Hussin wrote:

> Hello.
>
> Sorry if that's considered laziness as I've just learnt R and didn't  
> know how important it is to do dput for all problems.
>
> If I was truly lazy then I wouldn't even bother to sign up here and  
> ask questions.
>
> Please be nicer next time.
>
> Suhaila.
>
> > CC: [hidden email]
> > From: [hidden email]
> > To: [hidden email]
> > Subject: Re: [R] Problem with Median
>
> > Date: Mon, 7 May 2012 20:25:24 -0400
> >
> >
> > On May 7, 2012, at 5:16 PM, Suhaila Haji Mohd Hussin wrote:
> >
> > >
> > > Hello.
> > > Now the median is solved but then I'm still figuring out how to  
> put
> > > the updated column back to replace the original column of the  
> whole
> > > data. I'll show you what I meant:
> > > Continuing from the previous commands you guys helped out I
> > > continued as followed:
> > > Original Data: http://i1165.photobucket.com/albums/q585/halfpirate/data.jpg
> > >
> > > Before column a: http://i1165.photobucket.com/albums/q585/halfpirate/1.jpg
> >
> > That fine for sending pictures to the family but NOT for  
> communicating
> > R code.
> > >
> > > 1) a.AC [is.na(a.AC)] <- median(a.AC$a, na.rm= TRUE)
> > > 2) a.ACAfter column a: http://i1165.photobucket.com/albums/q585/halfpirate/2.jpg
> > > 3) data$a <- a.ACGives me error that the original data has 6 rows
> > > yet the one I'm replacing is 1 row.
> > > I understand the error and I don't want to completely replace the
> > > column if I really want to.
> >
> > You were not attempting to replace the entire column, but you were
> > trying to replace 6 entries. So why not... :
> >
> > a.AC [is.na(a.AC)] <- rep( median(a.AC$a, na.rm= TRUE) , 6)
> >
> >
> > > Basically I'm expecting the result to be like this. After you
> > > compare the original data, the final answer should be like thishttp://i1165.photobucket.com/albums/q585/halfpirate/3.jpg
> >
> > What part of "I can't do anything with your jpeg to answer your
> > questions about your dataframe" was difficult to understand? We do  
> NOT
> > want pictures from which we need to repeat data entry that you have
> > already done. The first virtue of a programmer being laziness.
> > Console output is also very ambiguous. Learn to use str() and dput()
> > or dump().
> >
> > ?dput
> > ?dump
> >
> > And run the examples. please.
> >
> > --
> > David.
> >
> >
> > > Please help.Suhaila
> > > From: [hidden email]
> > > To: [hidden email]
> > > CC: [hidden email]
> > > Subject: RE: [R] Problem with Median
> > > Date: Tue, 8 May 2012 07:22:19 +1200
> > >
> > > Thank you so much!
> > > Suhaila.
> > >
> > >> Date: Mon, 7 May 2012 15:08:47 -0400
> > >> Subject: Re: [R] Problem with Median
> > >> From: [hidden email]
> > >> To: [hidden email]
> > >>
> > >> Your problem is that a.AC is a dataframe:
> > >>
> > >>
> > >>> x <- read.table(text = " a b c class
> > >> + 1 12 0 90 A-B
> > >> + 2 3 97 11 A-B
> > >> + 3 78 NA 123 A-C
> > >> + 4 NA NA 12 A-C
> > >> + 5 8 33 2 A-B
> > >> + 6 12 NA 0 A-D", header = TRUE)
> > >>> a.AC <- subset(x, class == "A-C", select = a)
> > >>> # same error
> > >>> median(a.AC)
> > >> Error in median.default(a.AC) : need numeric data
> > >>
> > >>> # now look a the structure of a.AC (its a dataframe)
> > >>> str(a.AC)
> > >> 'data.frame': 2 obs. of 1 variable:
> > >> $ a: int 78 NA
> > >>> # now do it right
> > >>> median(a.AC$a)
> > >> [1] NA
> > >>> median(a.AC$a, na.rm = TRUE)
> > >> [1] 78
> > >>
> > >>
> > >>
> > >> On Mon, May 7, 2012 at 2:52 PM, Suhaila Haji Mohd Hussin
> > >> <[hidden email]> 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
> > >>> [[alternative HTML version deleted]]
> > >>>
> > >>> ______________________________________________
> > >>> [hidden email] 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.
> > >>
> > >>
> > >>
> > >> --
> > >> Jim Holtman
> > >> Data Munger Guru
> > >>
> > >> What is the problem that you are trying to solve?
> > >> Tell me what you want to do, not how you want to do it.
> > >
> > >
> > > I might be silly but if I was going to type in dput() then how
> > > should I send the data over here?
> > > 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: [hidden email]
> > >> To: [hidden email]
> > >> CC: [hidden email]
> > >>
> > >> 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
> > >> <[hidden email]> 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
> > >
> > >
> > > [[alternative HTML version deleted]]
> > >
> > > ______________________________________________
> > > [hidden email] 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.
> >
> > David Winsemius, MD
> > West Hartford, CT
> >

David Winsemius, MD
West Hartford, CT


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Problem with Median

David Winsemius
In reply to this post by Suhaila Haji Mohd Hussin

On May 8, 2012, at 4:35 AM, Suhaila Haji Mohd Hussin wrote:

> Hello.
>
> Sorry if that's considered laziness as I've just learnt R and didn't  
> know how important it is to do dput for all problems.
>
> If I was truly lazy then I wouldn't even bother to sign up here and  
> ask questions.

I didn't say you were lazy. I implied that you were being  
insufficiently lazy. It would have been much easier  (had you read the  
Posting Guide and been properly lazy) to use either dump or dput to  
post machine readable versions of your data than to make a jpg and  
post it on an external website.

  I considered, but then decided that it was probablyunnecessary,  
offering a link to what is a fairly famous piece by Larry Wall  
explaining that one _should_ be lazy if one wants to be a good  
programmer. The Three Virtues: Laziness, Impatience, Hubris:

http://c2.com/cgi/wiki?LazinessImpatienceHubris

--
David.

>
> Please be nicer next time.
>
> Suhaila.
>
> > CC: [hidden email]
> > From: [hidden email]
> > To: [hidden email]
> > Subject: Re: [R] Problem with Median
>
> > Date: Mon, 7 May 2012 20:25:24 -0400
> >
> >
> > On May 7, 2012, at 5:16 PM, Suhaila Haji Mohd Hussin wrote:
> >
> > >
> > > Hello.
> > > Now the median is solved but then I'm still figuring out how to  
> put
> > > the updated column back to replace the original column of the  
> whole
> > > data. I'll show you what I meant:
> > > Continuing from the previous commands you guys helped out I
> > > continued as followed:
> > > Original Data: http://i1165.photobucket.com/albums/q585/halfpirate/data.jpg
> > >
> > > Before column a: http://i1165.photobucket.com/albums/q585/halfpirate/1.jpg
> >
> > That fine for sending pictures to the family but NOT for  
> communicating
> > R code.
> > >
> > > 1) a.AC [is.na(a.AC)] <- median(a.AC$a, na.rm= TRUE)
> > > 2) a.ACAfter column a: http://i1165.photobucket.com/albums/q585/halfpirate/2.jpg
> > > 3) data$a <- a.ACGives me error that the original data has 6 rows
> > > yet the one I'm replacing is 1 row.
> > > I understand the error and I don't want to completely replace the
> > > column if I really want to.
> >
> > You were not attempting to replace the entire column, but you were
> > trying to replace 6 entries. So why not... :
> >
> > a.AC [is.na(a.AC)] <- rep( median(a.AC$a, na.rm= TRUE) , 6)
> >
> >
> > > Basically I'm expecting the result to be like this. After you
> > > compare the original data, the final answer should be like thishttp://i1165.photobucket.com/albums/q585/halfpirate/3.jpg
> >
> > What part of "I can't do anything with your jpeg to answer your
> > questions about your dataframe" was difficult to understand? We do  
> NOT
> > want pictures from which we need to repeat data entry that you have
> > already done. The first virtue of a programmer being laziness.
> > Console output is also very ambiguous. Learn to use str() and dput()
> > or dump().
> >
> > ?dput
> > ?dump
> >
> > And run the examples. please.
> >
> > --
> > David.
> >
> >
> > > Please help.Suhaila
> > > From: [hidden email]
> > > To: [hidden email]
> > > CC: [hidden email]
> > > Subject: RE: [R] Problem with Median
> > > Date: Tue, 8 May 2012 07:22:19 +1200
> > >
> > > Thank you so much!
> > > Suhaila.
> > >
> > >> Date: Mon, 7 May 2012 15:08:47 -0400
> > >> Subject: Re: [R] Problem with Median
> > >> From: [hidden email]
> > >> To: [hidden email]
> > >>
> > >> Your problem is that a.AC is a dataframe:
> > >>
> > >>
> > >>> x <- read.table(text = " a b c class
> > >> + 1 12 0 90 A-B
> > >> + 2 3 97 11 A-B
> > >> + 3 78 NA 123 A-C
> > >> + 4 NA NA 12 A-C
> > >> + 5 8 33 2 A-B
> > >> + 6 12 NA 0 A-D", header = TRUE)
> > >>> a.AC <- subset(x, class == "A-C", select = a)
> > >>> # same error
> > >>> median(a.AC)
> > >> Error in median.default(a.AC) : need numeric data
> > >>
> > >>> # now look a the structure of a.AC (its a dataframe)
> > >>> str(a.AC)
> > >> 'data.frame': 2 obs. of 1 variable:
> > >> $ a: int 78 NA
> > >>> # now do it right
> > >>> median(a.AC$a)
> > >> [1] NA
> > >>> median(a.AC$a, na.rm = TRUE)
> > >> [1] 78
> > >>
> > >>
> > >>
> > >> On Mon, May 7, 2012 at 2:52 PM, Suhaila Haji Mohd Hussin
> > >> <[hidden email]> 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
> > >>> [[alternative HTML version deleted]]
> > >>>
> > >>> ______________________________________________
> > >>> [hidden email] 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.
> > >>
> > >>
> > >>
> > >> --
> > >> Jim Holtman
> > >> Data Munger Guru
> > >>
> > >> What is the problem that you are trying to solve?
> > >> Tell me what you want to do, not how you want to do it.
> > >
> > >
> > > I might be silly but if I was going to type in dput() then how
> > > should I send the data over here?
> > > 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: [hidden email]
> > >> To: [hidden email]
> > >> CC: [hidden email]
> > >>
> > >> 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
> > >> <[hidden email]> 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
> > >
> > >
> > > [[alternative HTML version deleted]]
> > >
> > > ______________________________________________
> > > [hidden email] 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.
> >
> > David Winsemius, MD
> > West Hartford, CT
> >

David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Problem with Median

PIKAL Petr
In reply to this post by Suhaila Haji Mohd Hussin
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: [hidden email]
> > To: [hidden email]
> > CC: [hidden email]
> >
> > 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
> > <[hidden email]> 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
>                       ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Transform Data using Sigmoid Function

Suhaila Haji Mohd Hussin
In reply to this post by Suhaila Haji Mohd Hussin

Hello.
I'm trying to scaling these attribute values using sigmoid and I created a function as followed:
mySigmoid <-function(){ medGen = read.csv("medB1.csv"); data(medGen); medGen.signorm=rangenorm(medGen,method="signorm"); op=par(mfrow=c(2,3)) plot(medGen.signorm[,1]) par(op)}
So as I source the function and typed in mySigmoid() the error message gave me 'But the error said
Error in mySigmoid() : could not find function "rangenorm"In addition: Warning message:In data(medGen) : data set ‘medGen’ not found
My attribute values:
structure(list(b1 = c(0L, 53L, 0L, 215L, 76L, 0L, 0L, 45L, 0L, 80L, 0L, 90L, 196L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 10L, 25L, 0L, 70L, 0L, 36L, 0L, 0L, 0L, 0L, 5L, 0L, 76L, 16L, 0L, 26L, 0L, 65L, 50L, 0L, 0L, 0L, 60L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 20L, 0L, 0L, 0L, 0L, 13L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 83L, 0L, 120L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 53L, 0L, 0L, 0L, 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0L, 0L, 0L, 10L, 70L, 0L, 0L, 0L, 0L, 0L, 0L, 170L, 55L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 75L, 0L, 50L, 0L, 100L, 0L, 0L, 10L, 0L, 0L, 0L, 0L, 50L, 0L, 0L, 0L, 0L, 20L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 85L, 0L, 0L, 0L, 0L, 0L, 110L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 35L, 0L, 0L, 0L, 0L, 0L, 0L, 60L, 0L, 0L, 0L, 30L, 0L, 0L, 0L, 0L, 0L, 160L, 0L, 0L, 0L, 0L, 0L, 0L, 10L, 0L, 0L, 0L, 0L, 0L, 0L, 35L, 0L, 0L, 0L, 0L, 0L, 0L, 30L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 65L, 0L, 0L, 0L, 0L, 0L, 300L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 27L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 40L, 0L, 0L, 0L, 0L, 0L, 35L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 180L, 95L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 125L, 0L, 0L, 0L, 0L, 10L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L)), .Names = "b1", class = "data.frame", row.names = c(NA, -1076L))
Please help,Suhaila    
         
        [[alternative HTML version deleted]]


______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Transform Data using Sigmoid Function

Suhaila Haji Mohd Hussin

Please nevermind as I have just solved this.
Suhaila

From: [hidden email]
To: [hidden email]
Date: Sat, 12 May 2012 20:44:16 +1200
Subject: [R] Transform Data using Sigmoid Function

 
Hello.
I'm trying to scaling these attribute values using sigmoid and I created a function as followed:
mySigmoid <-function(){ medGen = read.csv("medB1.csv"); data(medGen); medGen.signorm=rangenorm(medGen,method="signorm"); op=par(mfrow=c(2,3)) plot(medGen.signorm[,1]) par(op)}
So as I source the function and typed in mySigmoid() the error message gave me 'But the error said
Error in mySigmoid() : could not find function "rangenorm"In addition: Warning message:In data(medGen) : data set ‘medGen’ not found
My attribute values:
structure(list(b1 = c(0L, 53L, 0L, 215L, 76L, 0L, 0L, 45L, 0L, 80L, 0L, 90L, 196L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 10L, 25L, 0L, 70L, 0L, 36L, 0L, 0L, 0L, 0L, 5L, 0L, 76L, 16L, 0L, 26L, 0L, 65L, 50L, 0L, 0L, 0L, 60L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 20L, 0L, 0L, 0L, 0L, 13L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 83L, 0L, 120L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 53L, 0L, 0L, 0L, 0L, 13L, 83L, 0L, 0L, 0L, 0L, 0L, 0L, 7L, 0L, 0L, 0L, 0L, 0L, 0L, 60L, 0L, 0L, 10L, 0L, 23L, 0L, 0L, 0L, 60L, 0L, 0L, 0L, 0L, 13L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 16L, 36L, 0L, 13L, 0L, 23L, 13L, 0L, 100L, 0L, 0L, 43L, 0L, 31L, 0L, 0L, 0L, 0L, 0L, 30L, 0L, 0L, 0L, 80L, 0L, 23L, 0L, 0L, 0L, 0L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, 0L, 0L, 0L, 85L, 0L, 0L, 0L, 0L, 0L, 110L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 35L, 0L, 0L, 0L, 0L, 0L, 0L, 60L, 0L, 0L, 0L, 30L, 0L, 0L, 0L, 0L, 0L, 160L, 0L, 0L, 0L, 0L, 0L, 0L, 10L, 0L, 0L, 0L, 0L, 0L, 0L, 35L, 0L, 0L, 0L, 0L, 0L, 0L, 30L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 65L, 0L, 0L, 0L, 0L, 0L, 300L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 27L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 40L, 0L, 0L, 0L, 0L, 0L, 35L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 180L, 95L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 125L, 0L, 0L, 0L, 0L, 10L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L)), .Names = "b1", class = "data.frame", row.names = c(NA, -1076L))
Please help,Suhaila    
         
        [[alternative HTML version deleted]]
 

______________________________________________
[hidden email] 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.    
        [[alternative HTML version deleted]]


______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

plot.ts error: cannot plot more than 10 series

Suhaila Haji Mohd Hussin

Hello.    
I'm doing Principal Component Analysis. So I'm trying to plot the new data as time series like this:
plot.ts(pr2$x)
But it gives me error: Error in plotts(x = x, y = y, plot.type = plot.type, xy.labels = xy.labels,  :  cannot plot more than 10 series as "multiple"
Here's my data dput it's really long so I just put in some essential information only for you to see:
structure(list(sdev = c(163.444257295666, 104.206376841326, 97.9593394161277, 85.13008012602, 78.672940030061, 73.7044913582009, 68.9919940515061, 66.4914391167912, 63.5364862493486, 53.0067010985736, 50.3850160673695, 41.0505058921616, 36.6847894205371, 34.4922997539369, 32.8160496561452), rotation = structure(c(-0.341624025780871, -0.465361625382171, -0.254733743609541, -0.501601736275946, -0.32909803586058, 0.10346905261603, 0.0826920791661065, 0.04180674828032, 0.0317514777236264, -0.041673145049323, 0.00552096153263742, 0.302880866160923, 0.0611515661970536, -0.19666860832608, -0.0512002313448844, 0.0532192307778435, -0.279691445123637, -0.0330375822617488, 0.0296862808186525, 0.00754185914289494, -0.0483037204914515, -0.145633004945105, 0.0663131380872606, ...................................0.018728860610997, -0.867607192081349, -0.00746836023138116, -0.197845760644588, 0.354006015245109, -0.0234568336704251, 0.17996661095123, 0.0910352921083386, 0.118413710329641), .D!
 im = c(20L, 15L), .Dimnames = list(    c("er", "pr", "ar", "l1", "l2", "b1", "b2", "h1", "h2", "h3",     "p1", "p2", "o1", "o2", "o3", "o4", "o5", "o6", "o7", "o8"    ), c("PC1", "PC2", "PC3", "PC4", "PC5", "PC6", "PC7", "PC8",     "PC9", "PC10", "PC11", "PC12", "PC13", "PC14", "PC15"))),     center = structure(c(94.4986072423398, 94.9637883008357,     71.1838440111421, 179.793871866295, 180.57938718663, 12.6490250696379,     10.5292479108635, 10.8690807799443, 38.2479108635098, 137.543175487465,     0.612813370473538, 45.150417827298, 10.5459610027855, 91.3259052924791,     116.885793871866, 59.0055710306407, 172.598885793872, 14.3676880222841,     5.0974930362117, 3.8857938718663), .Names = c("er", "pr",     "ar", "l1", "l2", "b1", "b2", "h1", "h2", "h3", "p1", "p2",     "o1", "o2", "o3", "o4", "o5", "o6", "o7", "o8")), scale = FALSE,     x = structure(c(-38.7640736739586, -85.3987965131485, 279.953119866405,     121.49850702536, 348.387859356463, -149.756720052989, 114.1!
 99587790773,     -258.129158201887, 245.434330475019, -74.518625315929
, 114.858457403311,     246.989390591038, 264.221327740388, -59.7706080070487, -66.9519268984565,     -202.267758377027, -61.2743296889704, -63.3534745591336, .................................................
403375504553, 41.2280423622485,     78.1688899057297, -17.9229807680497, 1.892930692659, -0.121464277679548,     -10.9161618391865, 9.77739319210259, -30.4117535843182), .Dim = c(359L,     15L), .Dimnames = list(c("9", "12", "13", "14", "18", "22",     "24", "29", "30", "31", "32", "33", "34", "44", "49", "53",     "54", "58", "59", "60", "62", "66", "69", "70", "75", "76",     "80", "87", "88", "93", "94", "96", "100", "101", "102",     "106", "114", "115", "116", "126", "128", "129", "131", "133",     "135", "137", "139", "141", "142", "144", "147", "151", "154",     "157", "158", "160", "161", "164", "169", "170", "171", "175",     "179", "180", "181", "186", "193", "195", "200", "205", "206",     "209", "218", "220", "221", "222", "224", "225", "226", "228",     "231", "232", "233", "235", "239", "243", "244", "253", "256",     "260", "264", "265", "266", "268", "269", "272", "275", "280", .........................................................   "1025", "1032", "1033"!
 , "1035", "1036", "1038", "1039", "1041",     "1042", "1046", "1047", "1048", "1051", "1055", "1059", "1060",     "1064", "1072", "1076"), c("PC1", "PC2", "PC3", "PC4", "PC5",     "PC6", "PC7", "PC8", "PC9", "PC10", "PC11", "PC12", "PC13",     "PC14", "PC15")))), .Names = c("sdev", "rotation", "center", "scale", "x"), class = "prcomp")
Please help,Suhaila    
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: plot.ts error: cannot plot more than 10 series

Gabor Grothendieck
On Sun, May 13, 2012 at 5:02 AM, Suhaila Haji Mohd Hussin
<[hidden email]> wrote:

>
> Hello.
> I'm doing Principal Component Analysis. So I'm trying to plot the new data as time series like this:
> plot.ts(pr2$x)
> But it gives me error: Error in plotts(x = x, y = y, plot.type = plot.type, xy.labels = xy.labels,  :  cannot plot more than 10 series as "multiple"
> Here's my data dput it's really long so I just put in some essential information only for you to see:
> structure(list(sdev = c(163.444257295666, 104.206376841326, 97.9593394161277, 85.13008012602, 78.672940030061, 73.7044913582009, 68.9919940515061, 66.4914391167912, 63.5364862493486, 53.0067010985736, 50.3850160673695, 41.0505058921616, 36.6847894205371, 34.4922997539369, 32.8160496561452), rotation = structure(c(-0.341624025780871, -0.465361625382171, -0.254733743609541, -0.501601736275946, -0.32909803586058, 0.10346905261603, 0.0826920791661065, 0.04180674828032, 0.0317514777236264, -0.041673145049323, 0.00552096153263742, 0.302880866160923, 0.0611515661970536, -0.19666860832608, -0.0512002313448844, 0.0532192307778435, -0.279691445123637, -0.0330375822617488, 0.0296862808186525, 0.00754185914289494, -0.0483037204914515, -0.145633004945105, 0.0663131380872606, ...................................0.018728860610997, -0.867607192081349, -0.00746836023138116, -0.197845760644588, 0.354006015245109, -0.0234568336704251, 0.17996661095123, 0.0910352921083386, 0.118413710329641), .D!
>  im = c(20L, 15L), .Dimnames = list(    c("er", "pr", "ar", "l1", "l2", "b1", "b2", "h1", "h2", "h3",     "p1", "p2", "o1", "o2", "o3", "o4", "o5", "o6", "o7", "o8"    ), c("PC1", "PC2", "PC3", "PC4", "PC5", "PC6", "PC7", "PC8",     "PC9", "PC10", "PC11", "PC12", "PC13", "PC14", "PC15"))),     center = structure(c(94.4986072423398, 94.9637883008357,     71.1838440111421, 179.793871866295, 180.57938718663, 12.6490250696379,     10.5292479108635, 10.8690807799443, 38.2479108635098, 137.543175487465,     0.612813370473538, 45.150417827298, 10.5459610027855, 91.3259052924791,     116.885793871866, 59.0055710306407, 172.598885793872, 14.3676880222841,     5.0974930362117, 3.8857938718663), .Names = c("er", "pr",     "ar", "l1", "l2", "b1", "b2", "h1", "h2", "h3", "p1", "p2",     "o1", "o2", "o3", "o4", "o5", "o6", "o7", "o8")), scale = FALSE,     x = structure(c(-38.7640736739586, -85.3987965131485, 279.953119866405,     121.49850702536, 348.387859356463, -149.756720052989, 114.1!
>  99587790773,     -258.129158201887, 245.434330475019, -74.518625315929
> , 114.858457403311,     246.989390591038, 264.221327740388, -59.7706080070487, -66.9519268984565,     -202.267758377027, -61.2743296889704, -63.3534745591336, .................................................
> 403375504553, 41.2280423622485,     78.1688899057297, -17.9229807680497, 1.892930692659, -0.121464277679548,     -10.9161618391865, 9.77739319210259, -30.4117535843182), .Dim = c(359L,     15L), .Dimnames = list(c("9", "12", "13", "14", "18", "22",     "24", "29", "30", "31", "32", "33", "34", "44", "49", "53",     "54", "58", "59", "60", "62", "66", "69", "70", "75", "76",     "80", "87", "88", "93", "94", "96", "100", "101", "102",     "106", "114", "115", "116", "126", "128", "129", "131", "133",     "135", "137", "139", "141", "142", "144", "147", "151", "154",     "157", "158", "160", "161", "164", "169", "170", "171", "175",     "179", "180", "181", "186", "193", "195", "200", "205", "206",     "209", "218", "220", "221", "222", "224", "225", "226", "228",     "231", "232", "233", "235", "239", "243", "244", "253", "256",     "260", "264", "265", "266", "268", "269", "272", "275", "280", .........................................................   "1025", "1032", "1033"!
>  , "1035", "1036", "1038", "1039", "1041",     "1042", "1046", "1047", "1048", "1051", "1055", "1059", "1060",     "1064", "1072", "1076"), c("PC1", "PC2", "PC3", "PC4", "PC5",     "PC6", "PC7", "PC8", "PC9", "PC10", "PC11", "PC12", "PC13",     "PC14", "PC15")))), .Names = c("sdev", "rotation", "center", "scale", "x"), class = "prcomp")
> Please help,Suhaila


The dput output seems to have gotten messed up in transmission so lets
use an artificial example:

set.seed(123)
DF <- as.data.frame(matrix(rnorm(600), nc = 12)) # 12 columns
p <- prcomp(DF)

# error - cannot plot more than 10
plot.ts(p$x)

# try it several ways with plot.zoo

library(zoo)
plot(as.zoo(p$x)) # ok

# or - all on one panel

k <- ncol(p$x)
plot(as.zoo(p$x), screen = 1, col = 1:k)

# or - 1st two on 1st panel, 2nd two on 2nd panel, etc.

plot(as.zoo(p$x), screen = seq(0, len = k) %/% 2, col = 1:2)

--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: plot.ts error: cannot plot more than 10 series

Suhaila Haji Mohd Hussin

Thank you!
Suhaila

> From: [hidden email]
> Date: Sun, 13 May 2012 07:58:19 -0400
> Subject: Re: [R] plot.ts error: cannot plot more than 10 series
> To: [hidden email]
> CC: [hidden email]
>
> On Sun, May 13, 2012 at 5:02 AM, Suhaila Haji Mohd Hussin
> <[hidden email]> wrote:
> >
> > Hello.
> > I'm doing Principal Component Analysis. So I'm trying to plot the new data as time series like this:
> > plot.ts(pr2$x)
> > But it gives me error: Error in plotts(x = x, y = y, plot.type = plot.type, xy.labels = xy.labels,  :  cannot plot more than 10 series as "multiple"
> > Here's my data dput it's really long so I just put in some essential information only for you to see:
> > structure(list(sdev = c(163.444257295666, 104.206376841326, 97.9593394161277, 85.13008012602, 78.672940030061, 73.7044913582009, 68.9919940515061, 66.4914391167912, 63.5364862493486, 53.0067010985736, 50.3850160673695, 41.0505058921616, 36.6847894205371, 34.4922997539369, 32.8160496561452), rotation = structure(c(-0.341624025780871, -0.465361625382171, -0.254733743609541, -0.501601736275946, -0.32909803586058, 0.10346905261603, 0.0826920791661065, 0.04180674828032, 0.0317514777236264, -0.041673145049323, 0.00552096153263742, 0.302880866160923, 0.0611515661970536, -0.19666860832608, -0.0512002313448844, 0.0532192307778435, -0.279691445123637, -0.0330375822617488, 0.0296862808186525, 0.00754185914289494, -0.0483037204914515, -0.145633004945105, 0.0663131380872606, ...................................0.018728860610997, -0.867607192081349, -0.00746836023138116, -0.197845760644588, 0.354006015245109, -0.0234568336704251, 0.17996661095123, 0.0910352921083386, 0.118413710329641)!
 , .D!
> >  im = c(20L, 15L), .Dimnames = list(    c("er", "pr", "ar", "l1", "l2", "b1", "b2", "h1", "h2", "h3",     "p1", "p2", "o1", "o2", "o3", "o4", "o5", "o6", "o7", "o8"    ), c("PC1", "PC2", "PC3", "PC4", "PC5", "PC6", "PC7", "PC8",     "PC9", "PC10", "PC11", "PC12", "PC13", "PC14", "PC15"))),     center = structure(c(94.4986072423398, 94.9637883008357,     71.1838440111421, 179.793871866295, 180.57938718663, 12.6490250696379,     10.5292479108635, 10.8690807799443, 38.2479108635098, 137.543175487465,     0.612813370473538, 45.150417827298, 10.5459610027855, 91.3259052924791,     116.885793871866, 59.0055710306407, 172.598885793872, 14.3676880222841,     5.0974930362117, 3.8857938718663), .Names = c("er", "pr",     "ar", "l1", "l2", "b1", "b2", "h1", "h2", "h3", "p1", "p2",     "o1", "o2", "o3", "o4", "o5", "o6", "o7", "o8")), scale = FALSE,     x = structure(c(-38.7640736739586, -85.3987965131485, 279.953119866405,     121.49850702536, 348.387859356463, -149.756720052989, 1!
 14.1!
> >  99587790773,     -258.129158201887, 245.434330475019, -74.518625315929
> > , 114.858457403311,     246.989390591038, 264.221327740388, -59.7706080070487, -66.9519268984565,     -202.267758377027, -61.2743296889704, -63.3534745591336, .................................................
> > 403375504553, 41.2280423622485,     78.1688899057297, -17.9229807680497, 1.892930692659, -0.121464277679548,     -10.9161618391865, 9.77739319210259, -30.4117535843182), .Dim = c(359L,     15L), .Dimnames = list(c("9", "12", "13", "14", "18", "22",     "24", "29", "30", "31", "32", "33", "34", "44", "49", "53",     "54", "58", "59", "60", "62", "66", "69", "70", "75", "76",     "80", "87", "88", "93", "94", "96", "100", "101", "102",     "106", "114", "115", "116", "126", "128", "129", "131", "133",     "135", "137", "139", "141", "142", "144", "147", "151", "154",     "157", "158", "160", "161", "164", "169", "170", "171", "175",     "179", "180", "181", "186", "193", "195", "200", "205", "206",     "209", "218", "220", "221", "222", "224", "225", "226", "228",     "231", "232", "233", "235", "239", "243", "244", "253", "256",     "260", "264", "265", "266", "268", "269", "272", "275", "280", .........................................................   "1025", "1032", "1!
 033"!

> >  , "1035", "1036", "1038", "1039", "1041",     "1042", "1046", "1047", "1048", "1051", "1055", "1059", "1060",     "1064", "1072", "1076"), c("PC1", "PC2", "PC3", "PC4", "PC5",     "PC6", "PC7", "PC8", "PC9", "PC10", "PC11", "PC12", "PC13",     "PC14", "PC15")))), .Names = c("sdev", "rotation", "center", "scale", "x"), class = "prcomp")
> > Please help,Suhaila
>
>
> The dput output seems to have gotten messed up in transmission so lets
> use an artificial example:
>
> set.seed(123)
> DF <- as.data.frame(matrix(rnorm(600), nc = 12)) # 12 columns
> p <- prcomp(DF)
>
> # error - cannot plot more than 10
> plot.ts(p$x)
>
> # try it several ways with plot.zoo
>
> library(zoo)
> plot(as.zoo(p$x)) # ok
>
> # or - all on one panel
>
> k <- ncol(p$x)
> plot(as.zoo(p$x), screen = 1, col = 1:k)
>
> # or - 1st two on 1st panel, 2nd two on 2nd panel, etc.
>
> plot(as.zoo(p$x), screen = seq(0, len = k) %/% 2, col = 1:2)
>
> --
> Statistics & Software Consulting
> GKX Group, GKX Associates Inc.
> tel: 1-877-GKX-GROUP
> email: ggrothendieck at gmail.com
     
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Couldn't plot all PCA new attributes on K-Means Clustering

Suhaila Haji Mohd Hussin
In reply to this post by Gabor Grothendieck

Hello.
I'm trying to plot clusters for all possible combination of attributes.
So I typed in
plot(pr2NewMedicalData, col = kmpr2NewMedicalData$cluster)
The problem is it only plots PC2 axis against PC1 axis. There should be PC1 to PC10. I tried it on normal data (not PCA) and it plots all possible combination of attributes.
Here's the data before applying K-means clustering. It's too long so I just show you some essential information;
structure(c(8.18794213444232, 108.09939741361, -129.331704413972, 245.596491781615, 284.97336181805, 46.2393277833597, 102.670149102092, ........................................-56.0868873906073, 78.7111917257909, 17.2805919727568, 8.21955994418973, -52.8841201560606), .Dim = c(1076L, 10L), .Dimnames = list(NULL,     c("PC1", "PC2", "PC3", "PC4", "PC5", "PC6", "PC7", "PC8",     "PC9", "PC10")))
And here's the data after applying K-means clustering. It's too long as well so I just show you some essential information only;
structure(list(cluster = c(2L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, .........................................1L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L), centers = structure(c(202.683498408051, -91.234890118988, -6.32822645738145, 2.84855476653021, 7.14162520784024, -3.21469382670974, 9.13147239059093, -4.11039323242235, -2.71400953442991, 1.22167005997248, 2.69685863804327, -1.21394984515696, -1.19187335000922, 0.536503637335695, 0.509142465076951, -0.229182726867495, 4.82054598771028, -2.16989536374021, 4.66753734226828, -2.10102085218006), .Dim = c(2L, 10L), .Dimnames = list(c("1", "2"), c("PC1", "PC2", "PC3", "PC4", "PC5", "PC6", "PC7", "PC8", "PC9", "PC10"))), totss = 86060500.4826787,     withinss = c(21892651.1737651, 44156468.7023972), tot.withinss = 66049119.8761623,     betweenss = 20011380.6065164, size = c(334L, 742L)), .Names = c("cluster", !
 "centers", "totss", "withinss", "tot.withinss", "betweenss", "size"), class = "kmeans")
Please help,Suhaila    
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Couldn't plot all PCA new attributes on K-Means Clustering

Suhaila Haji Mohd Hussin

Please nevermind as I've just solved this by using scatterplot matrices.
Suhaila

> From: [hidden email]
> To: [hidden email]
> Date: Mon, 14 May 2012 06:28:06 +1200
> Subject: [R] Couldn't plot all PCA new attributes on K-Means Clustering
>
>
> Hello.
> I'm trying to plot clusters for all possible combination of attributes.
> So I typed in
> plot(pr2NewMedicalData, col = kmpr2NewMedicalData$cluster)
> The problem is it only plots PC2 axis against PC1 axis. There should be PC1 to PC10. I tried it on normal data (not PCA) and it plots all possible combination of attributes.
> Here's the data before applying K-means clustering. It's too long so I just show you some essential information;
> structure(c(8.18794213444232, 108.09939741361, -129.331704413972, 245.596491781615, 284.97336181805, 46.2393277833597, 102.670149102092, ........................................-56.0868873906073, 78.7111917257909, 17.2805919727568, 8.21955994418973, -52.8841201560606), .Dim = c(1076L, 10L), .Dimnames = list(NULL,     c("PC1", "PC2", "PC3", "PC4", "PC5", "PC6", "PC7", "PC8",     "PC9", "PC10")))
> And here's the data after applying K-means clustering. It's too long as well so I just show you some essential information only;
> structure(list(cluster = c(2L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, .........................................1L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 2L), centers = structure(c(202.683498408051, -91.234890118988, -6.32822645738145, 2.84855476653021, 7.14162520784024, -3.21469382670974, 9.13147239059093, -4.11039323242235, -2.71400953442991, 1.22167005997248, 2.69685863804327, -1.21394984515696, -1.19187335000922, 0.536503637335695, 0.509142465076951, -0.229182726867495, 4.82054598771028, -2.16989536374021, 4.66753734226828, -2.10102085218006), .Dim = c(2L, 10L), .Dimnames = list(c("1", "2"), c("PC1", "PC2", "PC3", "PC4", "PC5", "PC6", "PC7", "PC8", "PC9", "PC10"))), totss = 86060500.4826787,     withinss = c(21892651.1737651, 44156468.7023972), tot.withinss = 66049119.8761623,     betweenss = 20011380.6065164, size = c(334L, 742L)), .Names = c("cluster"!
 , !
>  "centers", "totss", "withinss", "tot.withinss", "betweenss", "size"), class = "kmeans")
> Please help,Suhaila    
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.
     
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Error using rect.hclust

Suhaila Haji Mohd Hussin
In reply to this post by Suhaila Haji Mohd Hussin

Hello.
I'm trying to see clusters into a certain number of classes as seeing they are too many of them see entirely on dendrogram. So I did the following:
> d <- dist(as.matrix(medData))> hc <- hclust(d, method="average")> plot(hc)> plot(hc, hang = -1)
But when it came to this:> rect.hclust(hc, 3)Error in rect(m[which[n]] + 0.66, par("usr")[3L], m[which[n] + 1] + 0.33,  :   plot.new has not been called yet
Here's my dput for hc. It's too long so I'm just showing you the essential information:
structure(list(merge = structure(c(-716L, -698L, -758L, -257L, -186L, -519L, -38L, -532L, -797L, -70L, -955L, -389L, -869L, ...........................................1058L, 1065L, 1064L, 1060L, 1067L, 1068L, 1062L, 1037L, 1071L, 1073L, 1074L), .Dim = c(1075L, 2L)), height = c(10, 25.1793566240283, 31.6631867410376, 38.2753184180093, 40.7308237088326, 42.8835632847831, ..................................398.00063581242, 421.396275641104, 428.384890986889), order = c(407L, 42L, 106L, 601L, 576L, 247L, 249L, 237L, 643L, 226L, 62L, 543L, ....................................985L, 458L, 1063L), labels = NULL, method = "average", call = hclust(d = d,     method = "average"), dist.method = "euclidean"), .Names = c("merge", "height", "order", "labels", "method", "call", "dist.method"), class = "hclust")

Please help,Suhaila    
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Loading...