Re: [R] Ordering of facet_wrap() panels

2018-08-17 Thread Jeff Newmiller
The result does NOT depend on whether or how the data itself are sorted, but 
rather on how the levels of the factors in the data are sorted. Best results 
will be obtained if you modify the data frame factors before giving the data 
frame to ggplot. Doing so will allow all of the ggplot functions to work on a 
consistent set of data columns.

Some example ways to change the ordering:

factor(f, levels = sort(unique(f))) #alpha
factor(f, levels = unique(f)) #as first encountered in data
factor(f, levels = c("b","a","c")) #explicit
factor(f, levels = c("b","a","c"), labels=c("Ok","Best","Other") "#presentation 
coding

If for some reason you don't want to modify your original data, make a 
temporary copy of your data frame and set the appropriate factor levels for 
your presentation. However, it will then be up to you to avoid making 
substantive changes to the data records between multiple plots (views of the 
data).

On August 15, 2018 12:18:12 PM PDT, Stats Student  
wrote:
>Understood. Will review the docs again. 
>
>My data is from an external source which, among other things, ensures
>that it's sorted correctly. I was asking for a way to have ggplot use
>the ordering in place, instead of re-ordering everything. Apologies if
>it wasn't clear from the original post. 
>
>Anyway, if the data is correctly presorted, unique should work ok, I
>think. 
>
>
>
>
>On Aug 15, 2018, 9:23 AM, at 9:23 AM, Bert Gunter
> wrote:
>>1. Unless there is good reason to keep a reply private, always cc the
>>list.
>>This allows more brains, possible corrections, etc.
>>
>>2. Have you read ?factor and ?unique ? Always study the docs
>carefully.
>>They are generally terse but complete, especially the base docs, and
>>you
>>can often find your answers there.
>>
>>3. Your "solution" may work in this case, but if I understand
>correctly
>>what you're after,  won't in general. unique() gives the unique values
>>in
>>the order they appear, which may not be the order you want:
>>
>>## want ordering to be "a" < "b" < "c"
>>
>>> f <- rep(letters[3:1],2)
>>
>>> factor(f, levels = unique(f))
>>[1] c b a c b a
>>Levels: c b a  ## not your desired order
>>
>>Again, please consult the docs and perhaps a tutorial or two as
>>necessary.
>>
>>-- Bert
>>
>>
>>
>>On Wed, Aug 15, 2018 at 8:22 AM, Stats Student
>>
>>wrote:
>>
>>> Many thanks, Bert.
>>>
>>> I did -
>>>
>>> facet_wrap(~factor(var, levels=unique (var))
>>>
>>> And it seems to be working fine.
>>> Do you see any issues with this?
>>>
>>> I'm fairly new to R so want to make sure I'm not doing something
>>stupid.
>>>
>>> Thanks again.
>>>
>>> On Wed, Aug 15, 2018, 7:50 AM Bert Gunter 
>>wrote:
>>>
 See ?factor.

 You can either use ?ordered to create an ordered factor to sort the
 levels as you desire or sort them with factor(). e.g.

 > f <- factor(letters[3:1])
 > f
 [1] c b a
 Levels: a b c   ## default ordering

 > f <- factor(f, levels = letters[3:1])
 > f
 [1] c b a
 Levels: c b a  ## explicit ordering

 Cheers,
 Bert



 Bert Gunter

 "The trouble with having an open mind is that people keep coming
>>along
 and sticking things into it."
 -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

 On Wed, Aug 15, 2018 at 7:21 AM, Stats Student <
 stats.student4...@gmail.com> wrote:

> Hi, I am generating multiple charts with facet_wrap() and what
>what
>>I
> see, R/ggplot sorts the panels by the facet variable. So adding an
>>index to
> the facet variable (1 - bucket, 2 - bucket, etc) does solve the
>>sorting
> issue but it's ugly.
>
> I also read this post which, if I understand correctly, claims
>that
> ggplot should be using the initial ordering of the data for
>>ordering the
> charts (instead of ordering the data itself).
>
> https://mvuorre.github.io/post/2016/order-ggplot-panel-plots/
>
> Wondering if anyone knows how to direct ggplot use the initial
>>sorting
> of the data to order the panels.
>
> Thank you.
>
> __
> R-help@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.
>


>
>__
>R-help@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.

-- 
Sent from my phone. Please excuse my brevity.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the 

Re: [R] Ordering of facet_wrap() panels

2018-08-16 Thread Stats Student
Understood. Will review the docs again. 

My data is from an external source which, among other things, ensures that it's 
sorted correctly. I was asking for a way to have ggplot use the ordering in 
place, instead of re-ordering everything. Apologies if it wasn't clear from the 
original post. 

Anyway, if the data is correctly presorted, unique should work ok, I think. 




On Aug 15, 2018, 9:23 AM, at 9:23 AM, Bert Gunter  
wrote:
>1. Unless there is good reason to keep a reply private, always cc the
>list.
>This allows more brains, possible corrections, etc.
>
>2. Have you read ?factor and ?unique ? Always study the docs carefully.
>They are generally terse but complete, especially the base docs, and
>you
>can often find your answers there.
>
>3. Your "solution" may work in this case, but if I understand correctly
>what you're after,  won't in general. unique() gives the unique values
>in
>the order they appear, which may not be the order you want:
>
>## want ordering to be "a" < "b" < "c"
>
>> f <- rep(letters[3:1],2)
>
>> factor(f, levels = unique(f))
>[1] c b a c b a
>Levels: c b a  ## not your desired order
>
>Again, please consult the docs and perhaps a tutorial or two as
>necessary.
>
>-- Bert
>
>
>
>On Wed, Aug 15, 2018 at 8:22 AM, Stats Student
>
>wrote:
>
>> Many thanks, Bert.
>>
>> I did -
>>
>> facet_wrap(~factor(var, levels=unique (var))
>>
>> And it seems to be working fine.
>> Do you see any issues with this?
>>
>> I'm fairly new to R so want to make sure I'm not doing something
>stupid.
>>
>> Thanks again.
>>
>> On Wed, Aug 15, 2018, 7:50 AM Bert Gunter 
>wrote:
>>
>>> See ?factor.
>>>
>>> You can either use ?ordered to create an ordered factor to sort the
>>> levels as you desire or sort them with factor(). e.g.
>>>
>>> > f <- factor(letters[3:1])
>>> > f
>>> [1] c b a
>>> Levels: a b c   ## default ordering
>>>
>>> > f <- factor(f, levels = letters[3:1])
>>> > f
>>> [1] c b a
>>> Levels: c b a  ## explicit ordering
>>>
>>> Cheers,
>>> Bert
>>>
>>>
>>>
>>> Bert Gunter
>>>
>>> "The trouble with having an open mind is that people keep coming
>along
>>> and sticking things into it."
>>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>>
>>> On Wed, Aug 15, 2018 at 7:21 AM, Stats Student <
>>> stats.student4...@gmail.com> wrote:
>>>
 Hi, I am generating multiple charts with facet_wrap() and what what
>I
 see, R/ggplot sorts the panels by the facet variable. So adding an
>index to
 the facet variable (1 - bucket, 2 - bucket, etc) does solve the
>sorting
 issue but it's ugly.

 I also read this post which, if I understand correctly, claims that
 ggplot should be using the initial ordering of the data for
>ordering the
 charts (instead of ordering the data itself).

 https://mvuorre.github.io/post/2016/order-ggplot-panel-plots/

 Wondering if anyone knows how to direct ggplot use the initial
>sorting
 of the data to order the panels.

 Thank you.

 __
 R-help@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.

>>>
>>>

__
R-help@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.


Re: [R] Ordering of facet_wrap() panels

2018-08-15 Thread John
On Wed, 15 Aug 2018 07:21:55 -0700
Stats Student  wrote:

> Hi, I am generating multiple charts with facet_wrap() and what what I
> see, R/ggplot sorts the panels by the facet variable. So adding an
> index to the facet variable (1 - bucket, 2 - bucket, etc) does solve
> the sorting issue but it's ugly. 
> 
You should also be looking at the ggplot help mailing list.  Since you
did not supply an example of your code it is not possible to really see
if anything in it might be overriding ggplot's normal behavior.

JDougherty

__
R-help@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.


Re: [R] Ordering of facet_wrap() panels

2018-08-15 Thread Bert Gunter
1. Unless there is good reason to keep a reply private, always cc the list.
This allows more brains, possible corrections, etc.

2. Have you read ?factor and ?unique ? Always study the docs carefully.
They are generally terse but complete, especially the base docs, and you
can often find your answers there.

3. Your "solution" may work in this case, but if I understand correctly
what you're after,  won't in general. unique() gives the unique values in
the order they appear, which may not be the order you want:

## want ordering to be "a" < "b" < "c"

> f <- rep(letters[3:1],2)

> factor(f, levels = unique(f))
[1] c b a c b a
Levels: c b a  ## not your desired order

Again, please consult the docs and perhaps a tutorial or two as necessary.

-- Bert



On Wed, Aug 15, 2018 at 8:22 AM, Stats Student 
wrote:

> Many thanks, Bert.
>
> I did -
>
> facet_wrap(~factor(var, levels=unique (var))
>
> And it seems to be working fine.
> Do you see any issues with this?
>
> I'm fairly new to R so want to make sure I'm not doing something stupid.
>
> Thanks again.
>
> On Wed, Aug 15, 2018, 7:50 AM Bert Gunter  wrote:
>
>> See ?factor.
>>
>> You can either use ?ordered to create an ordered factor to sort the
>> levels as you desire or sort them with factor(). e.g.
>>
>> > f <- factor(letters[3:1])
>> > f
>> [1] c b a
>> Levels: a b c   ## default ordering
>>
>> > f <- factor(f, levels = letters[3:1])
>> > f
>> [1] c b a
>> Levels: c b a  ## explicit ordering
>>
>> Cheers,
>> Bert
>>
>>
>>
>> Bert Gunter
>>
>> "The trouble with having an open mind is that people keep coming along
>> and sticking things into it."
>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>
>> On Wed, Aug 15, 2018 at 7:21 AM, Stats Student <
>> stats.student4...@gmail.com> wrote:
>>
>>> Hi, I am generating multiple charts with facet_wrap() and what what I
>>> see, R/ggplot sorts the panels by the facet variable. So adding an index to
>>> the facet variable (1 - bucket, 2 - bucket, etc) does solve the sorting
>>> issue but it's ugly.
>>>
>>> I also read this post which, if I understand correctly, claims that
>>> ggplot should be using the initial ordering of the data for ordering the
>>> charts (instead of ordering the data itself).
>>>
>>> https://mvuorre.github.io/post/2016/order-ggplot-panel-plots/
>>>
>>> Wondering if anyone knows how to direct ggplot use the initial sorting
>>> of the data to order the panels.
>>>
>>> Thank you.
>>>
>>> __
>>> R-help@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.
>>>
>>
>>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Ordering of facet_wrap() panels

2018-08-15 Thread Bert Gunter
See ?factor.

You can either use ?ordered to create an ordered factor to sort the levels
as you desire or sort them with factor(). e.g.

> f <- factor(letters[3:1])
> f
[1] c b a
Levels: a b c   ## default ordering

> f <- factor(f, levels = letters[3:1])
> f
[1] c b a
Levels: c b a  ## explicit ordering

Cheers,
Bert



Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Wed, Aug 15, 2018 at 7:21 AM, Stats Student 
wrote:

> Hi, I am generating multiple charts with facet_wrap() and what what I see,
> R/ggplot sorts the panels by the facet variable. So adding an index to the
> facet variable (1 - bucket, 2 - bucket, etc) does solve the sorting issue
> but it's ugly.
>
> I also read this post which, if I understand correctly, claims that ggplot
> should be using the initial ordering of the data for ordering the charts
> (instead of ordering the data itself).
>
> https://mvuorre.github.io/post/2016/order-ggplot-panel-plots/
>
> Wondering if anyone knows how to direct ggplot use the initial sorting of
> the data to order the panels.
>
> Thank you.
>
> __
> R-help@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.
>

[[alternative HTML version deleted]]

__
R-help@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.


[R] Ordering of facet_wrap() panels

2018-08-15 Thread Stats Student
Hi, I am generating multiple charts with facet_wrap() and what what I see, 
R/ggplot sorts the panels by the facet variable. So adding an index to the 
facet variable (1 - bucket, 2 - bucket, etc) does solve the sorting issue but 
it's ugly. 

I also read this post which, if I understand correctly, claims that ggplot 
should be using the initial ordering of the data for ordering the charts 
(instead of ordering the data itself). 

https://mvuorre.github.io/post/2016/order-ggplot-panel-plots/

Wondering if anyone knows how to direct ggplot use the initial sorting of the 
data to order the panels. 

Thank you.

__
R-help@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.


Re: [R] Ordering Filenames stored in list or vector

2015-12-07 Thread BARLAS Marios 247554
Thanks a lot for the clarifying code Mark!

Actually, I took a lazy option and after some digging around I found out the 
package called "naturalsort" which provides a pretty compact solution!

As a rookie, I have another question. My main interest in R is that I hope to 
integrate in a scripting fashion good amount of data crunching coming from 
electrical measurements and at the same time give me a nice visualization 
option all in the same tool.

Is it a proper tool for such use in your experience? So far I was using Matlab 
+ OriginPro for treatment and visualization but now, starting my PhD I feel 
like I want something more "integrated"

Thanks,
Mario

From: Mark Sharp [msh...@txbiomed.org]
Sent: Friday, December 04, 2015 5:25 PM
To: BARLAS Marios 247554
Cc: r-help@r-project.org
Subject: Re: [R] Ordering Filenames stored in list or vector

Mario,

I am certain there are more elegant solutions. This is an effort to make the 
process clear by dividing out each transformation used into separate lines.

## Start of code
library(stringi) # This is written in C and C++ (ICU library), is fast, and is 
well documented.
filenames <- c("Q_Read_prist#1...@1.xls", "Q_Read_prist#1...@10.xls",
   "Q_Read_prist#1...@11.xls", "Q_Read_prist#1...@12.xls",
   "Q_Read_prist#1...@13.xls", "Q_Read_prist#1...@14.xls",
   "Q_Read_prist#1...@15.xls", "Q_Read_prist#1...@16.xls",
   "Q_Read_prist#1...@17.xls", "Q_Read_prist#1...@18.xls",
   "Q_Read_prist#1...@19.xls", "Q_Read_prist#1...@2.xls",
   "Q_Read_prist#1...@3.xls", "Q_Read_prist#1...@4.xls",
   "Q_Read_prist#1...@5.xls", "Q_Read_prist#1...@6.xls",
   "Q_Read_prist#1...@7.xls", "Q_Read_prist#1...@8.xls",
   "Q_Read_prist#1...@9.xls")
indx_list <- stri_split_regex(filenames, pattern = "[@.]")
indx <- sapply(indx_list, function(x) {x[[2]]})
filenames_df <- data.frame(file_name = filenames, indx = indx,
stringsAsFactors = FALSE)
filenames_ordered <- filenames_df[order(as.numeric(filenames_df$indx)),
"file_name"]
filenames_ordered
## end of code
Mark


R. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msh...@txbiomed.org







> On Dec 4, 2015, at 4:51 AM, BARLAS Marios 247554 <marios.bar...@cea.fr> wrote:
>
> Hello everyone,
>
> I am an R rookie and I'm learning as I program.
>
> I am working on a script to process a large amount of data: I read a pattern 
> of filenames in the folder I want and import their data
>
> filenames = list.files(path, pattern="*Q_Read_prist*")
>
> myfiles = lapply(filenames, function(x) read.xlsx2(file=x, sheetName="Data", 
> header=TRUE, FILENAMEVAR=x))
>
> The problem is that R recognizes the files in a 'non human' order.
>
> Q_Read_prist#1...@1.xls   Q_Read_prist#1...@1.xls
> Q_Read_prist#1...@10.xls Q_Read_prist#1...@10.xls
> Q_Read_prist#1...@11.xls Q_Read_prist#1...@11.xls
> Q_Read_prist#1...@12.xls Q_Read_prist#1...@12.xls
> Q_Read_prist#1...@13.xls Q_Read_prist#1...@13.xls
> Q_Read_prist#1...@14.xls Q_Read_prist#1...@14.xls
> Q_Read_prist#1...@15.xls Q_Read_prist#1...@15.xls
> Q_Read_prist#1...@16.xls Q_Read_prist#1...@16.xls
> Q_Read_prist#1...@17.xls Q_Read_prist#1...@17.xls
> Q_Read_prist#1...@18.xls Q_Read_prist#1...@18.xls
> Q_Read_prist#1...@19.xls Q_Read_prist#1...@19.xls
> Q_Read_prist#1...@2.xls   Q_Read_prist#1...@2.xls
> Q_Read_prist#1...@3.xls   Q_Read_prist#1...@3.xls
> Q_Read_prist#1...@4.xls   Q_Read_prist#1...@4.xls
> Q_Read_prist#1...@5.xls   Q_Read_prist#1...@5.xls
> Q_Read_prist#1...@6.xls   Q_Read_prist#1...@6.xls
> Q_Read_prist#1...@7.xls   Q_Read_prist#1...@7.xls
> Q_Read_prist#1...@8.xls   Q_Read_prist#1...@8.xls
> Q_Read_prist#1...@9.xls   Q_Read_prist#1...@9.xls
>
> I tried to order them using order or sort but it doesn' seem to work. I have 
> had the same issue in matlab but there I have a function to re-define the 
> order in a "correct" way.
>
> Anyone knows of a smart way to sort these guys from 1 to 19 ascending or 
> descending?
>
> Thanks in advance,
> Mario
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@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.

__
R-help@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.


[R] Ordering Filenames stored in list or vector

2015-12-04 Thread BARLAS Marios 247554
Hello everyone,

I am an R rookie and I'm learning as I program.

I am working on a script to process a large amount of data: I read a pattern of 
filenames in the folder I want and import their data

filenames = list.files(path, pattern="*Q_Read_prist*")

myfiles = lapply(filenames, function(x) read.xlsx2(file=x, sheetName="Data", 
header=TRUE, FILENAMEVAR=x))

The problem is that R recognizes the files in a 'non human' order.

Q_Read_prist#1...@1.xls   Q_Read_prist#1...@1.xls
Q_Read_prist#1...@10.xls Q_Read_prist#1...@10.xls
Q_Read_prist#1...@11.xls Q_Read_prist#1...@11.xls
Q_Read_prist#1...@12.xls Q_Read_prist#1...@12.xls
Q_Read_prist#1...@13.xls Q_Read_prist#1...@13.xls
Q_Read_prist#1...@14.xls Q_Read_prist#1...@14.xls
Q_Read_prist#1...@15.xls Q_Read_prist#1...@15.xls
Q_Read_prist#1...@16.xls Q_Read_prist#1...@16.xls
Q_Read_prist#1...@17.xls Q_Read_prist#1...@17.xls
Q_Read_prist#1...@18.xls Q_Read_prist#1...@18.xls
Q_Read_prist#1...@19.xls Q_Read_prist#1...@19.xls
Q_Read_prist#1...@2.xls   Q_Read_prist#1...@2.xls
Q_Read_prist#1...@3.xls   Q_Read_prist#1...@3.xls
Q_Read_prist#1...@4.xls   Q_Read_prist#1...@4.xls
Q_Read_prist#1...@5.xls   Q_Read_prist#1...@5.xls
Q_Read_prist#1...@6.xls   Q_Read_prist#1...@6.xls
Q_Read_prist#1...@7.xls   Q_Read_prist#1...@7.xls
Q_Read_prist#1...@8.xls   Q_Read_prist#1...@8.xls
Q_Read_prist#1...@9.xls   Q_Read_prist#1...@9.xls

I tried to order them using order or sort but it doesn' seem to work. I have 
had the same issue in matlab but there I have a function to re-define the order 
in a "correct" way.

Anyone knows of a smart way to sort these guys from 1 to 19 ascending or 
descending?

Thanks in advance,
Mario

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Ordering Filenames stored in list or vector

2015-12-04 Thread Boris Steipe
The thread below has a number of solutions. I personally like the one with 
sprintf().
   https://stat.ethz.ch/pipermail/r-help/2010-July/246059.html


B.

On Dec 4, 2015, at 5:51 AM, BARLAS Marios 247554  wrote:

> Hello everyone,
> 
> I am an R rookie and I'm learning as I program.
> 
> I am working on a script to process a large amount of data: I read a pattern 
> of filenames in the folder I want and import their data
> 
> filenames = list.files(path, pattern="*Q_Read_prist*")
> 
> myfiles = lapply(filenames, function(x) read.xlsx2(file=x, sheetName="Data", 
> header=TRUE, FILENAMEVAR=x))
> 
> The problem is that R recognizes the files in a 'non human' order.
> 
> Q_Read_prist#1...@1.xls   Q_Read_prist#1...@1.xls
> Q_Read_prist#1...@10.xls Q_Read_prist#1...@10.xls
> Q_Read_prist#1...@11.xls Q_Read_prist#1...@11.xls
> Q_Read_prist#1...@12.xls Q_Read_prist#1...@12.xls
> Q_Read_prist#1...@13.xls Q_Read_prist#1...@13.xls
> Q_Read_prist#1...@14.xls Q_Read_prist#1...@14.xls
> Q_Read_prist#1...@15.xls Q_Read_prist#1...@15.xls
> Q_Read_prist#1...@16.xls Q_Read_prist#1...@16.xls
> Q_Read_prist#1...@17.xls Q_Read_prist#1...@17.xls
> Q_Read_prist#1...@18.xls Q_Read_prist#1...@18.xls
> Q_Read_prist#1...@19.xls Q_Read_prist#1...@19.xls
> Q_Read_prist#1...@2.xls   Q_Read_prist#1...@2.xls
> Q_Read_prist#1...@3.xls   Q_Read_prist#1...@3.xls
> Q_Read_prist#1...@4.xls   Q_Read_prist#1...@4.xls
> Q_Read_prist#1...@5.xls   Q_Read_prist#1...@5.xls
> Q_Read_prist#1...@6.xls   Q_Read_prist#1...@6.xls
> Q_Read_prist#1...@7.xls   Q_Read_prist#1...@7.xls
> Q_Read_prist#1...@8.xls   Q_Read_prist#1...@8.xls
> Q_Read_prist#1...@9.xls   Q_Read_prist#1...@9.xls
> 
> I tried to order them using order or sort but it doesn' seem to work. I have 
> had the same issue in matlab but there I have a function to re-define the 
> order in a "correct" way.
> 
> Anyone knows of a smart way to sort these guys from 1 to 19 ascending or 
> descending?
> 
> Thanks in advance,
> Mario
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@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.

__
R-help@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.


Re: [R] Ordering Filenames stored in list or vector

2015-12-04 Thread Mark Sharp
Mario,

I am certain there are more elegant solutions. This is an effort to make the 
process clear by dividing out each transformation used into separate lines.

## Start of code
library(stringi) # This is written in C and C++ (ICU library), is fast, and is 
well documented.
filenames <- c("Q_Read_prist#1...@1.xls", "Q_Read_prist#1...@10.xls", 
   "Q_Read_prist#1...@11.xls", "Q_Read_prist#1...@12.xls", 
   "Q_Read_prist#1...@13.xls", "Q_Read_prist#1...@14.xls", 
   "Q_Read_prist#1...@15.xls", "Q_Read_prist#1...@16.xls", 
   "Q_Read_prist#1...@17.xls", "Q_Read_prist#1...@18.xls", 
   "Q_Read_prist#1...@19.xls", "Q_Read_prist#1...@2.xls", 
   "Q_Read_prist#1...@3.xls", "Q_Read_prist#1...@4.xls", 
   "Q_Read_prist#1...@5.xls", "Q_Read_prist#1...@6.xls", 
   "Q_Read_prist#1...@7.xls", "Q_Read_prist#1...@8.xls", 
   "Q_Read_prist#1...@9.xls")
indx_list <- stri_split_regex(filenames, pattern = "[@.]")
indx <- sapply(indx_list, function(x) {x[[2]]})
filenames_df <- data.frame(file_name = filenames, indx = indx, 
stringsAsFactors = FALSE)
filenames_ordered <- filenames_df[order(as.numeric(filenames_df$indx)), 
"file_name"]
filenames_ordered
## end of code
Mark


R. Mark Sharp, Ph.D.
Director of Primate Records Database
Southwest National Primate Research Center
Texas Biomedical Research Institute
P.O. Box 760549
San Antonio, TX 78245-0549
Telephone: (210)258-9476
e-mail: msh...@txbiomed.org







> On Dec 4, 2015, at 4:51 AM, BARLAS Marios 247554  wrote:
> 
> Hello everyone,
> 
> I am an R rookie and I'm learning as I program.
> 
> I am working on a script to process a large amount of data: I read a pattern 
> of filenames in the folder I want and import their data
> 
> filenames = list.files(path, pattern="*Q_Read_prist*")
> 
> myfiles = lapply(filenames, function(x) read.xlsx2(file=x, sheetName="Data", 
> header=TRUE, FILENAMEVAR=x))
> 
> The problem is that R recognizes the files in a 'non human' order.
> 
> Q_Read_prist#1...@1.xls   Q_Read_prist#1...@1.xls
> Q_Read_prist#1...@10.xls Q_Read_prist#1...@10.xls
> Q_Read_prist#1...@11.xls Q_Read_prist#1...@11.xls
> Q_Read_prist#1...@12.xls Q_Read_prist#1...@12.xls
> Q_Read_prist#1...@13.xls Q_Read_prist#1...@13.xls
> Q_Read_prist#1...@14.xls Q_Read_prist#1...@14.xls
> Q_Read_prist#1...@15.xls Q_Read_prist#1...@15.xls
> Q_Read_prist#1...@16.xls Q_Read_prist#1...@16.xls
> Q_Read_prist#1...@17.xls Q_Read_prist#1...@17.xls
> Q_Read_prist#1...@18.xls Q_Read_prist#1...@18.xls
> Q_Read_prist#1...@19.xls Q_Read_prist#1...@19.xls
> Q_Read_prist#1...@2.xls   Q_Read_prist#1...@2.xls
> Q_Read_prist#1...@3.xls   Q_Read_prist#1...@3.xls
> Q_Read_prist#1...@4.xls   Q_Read_prist#1...@4.xls
> Q_Read_prist#1...@5.xls   Q_Read_prist#1...@5.xls
> Q_Read_prist#1...@6.xls   Q_Read_prist#1...@6.xls
> Q_Read_prist#1...@7.xls   Q_Read_prist#1...@7.xls
> Q_Read_prist#1...@8.xls   Q_Read_prist#1...@8.xls
> Q_Read_prist#1...@9.xls   Q_Read_prist#1...@9.xls
> 
> I tried to order them using order or sort but it doesn' seem to work. I have 
> had the same issue in matlab but there I have a function to re-define the 
> order in a "correct" way.
> 
> Anyone knows of a smart way to sort these guys from 1 to 19 ascending or 
> descending?
> 
> Thanks in advance,
> Mario
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@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.

__
R-help@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.


Re: [R] Ordering Filenames stored in list or vector

2015-12-04 Thread Henrik Bengtsson
> filenames <- c("Q_Read_prist#1...@1.xls", "Q_Read_prist#1...@10.xls", 
> "Q_Read_prist#1...@2.xls")
> filenames <- gtools::mixedsort(filenames, numeric.type="decimal")
> filenames
[1] "Q_Read_prist#1...@1.xls"  "Q_Read_prist#1...@2.xls"  
"Q_Read_prist#1...@10.xls"

/Henrik

On Fri, Dec 4, 2015 at 7:53 AM, Boris Steipe  wrote:
> The thread below has a number of solutions. I personally like the one with 
> sprintf().
>https://stat.ethz.ch/pipermail/r-help/2010-July/246059.html
>
>
> B.
>
> On Dec 4, 2015, at 5:51 AM, BARLAS Marios 247554  wrote:
>
>> Hello everyone,
>>
>> I am an R rookie and I'm learning as I program.
>>
>> I am working on a script to process a large amount of data: I read a pattern 
>> of filenames in the folder I want and import their data
>>
>> filenames = list.files(path, pattern="*Q_Read_prist*")
>>
>> myfiles = lapply(filenames, function(x) read.xlsx2(file=x, sheetName="Data", 
>> header=TRUE, FILENAMEVAR=x))
>>
>> The problem is that R recognizes the files in a 'non human' order.
>>
>> Q_Read_prist#1...@1.xls   Q_Read_prist#1...@1.xls
>> Q_Read_prist#1...@10.xls Q_Read_prist#1...@10.xls
>> Q_Read_prist#1...@11.xls Q_Read_prist#1...@11.xls
>> Q_Read_prist#1...@12.xls Q_Read_prist#1...@12.xls
>> Q_Read_prist#1...@13.xls Q_Read_prist#1...@13.xls
>> Q_Read_prist#1...@14.xls Q_Read_prist#1...@14.xls
>> Q_Read_prist#1...@15.xls Q_Read_prist#1...@15.xls
>> Q_Read_prist#1...@16.xls Q_Read_prist#1...@16.xls
>> Q_Read_prist#1...@17.xls Q_Read_prist#1...@17.xls
>> Q_Read_prist#1...@18.xls Q_Read_prist#1...@18.xls
>> Q_Read_prist#1...@19.xls Q_Read_prist#1...@19.xls
>> Q_Read_prist#1...@2.xls   Q_Read_prist#1...@2.xls
>> Q_Read_prist#1...@3.xls   Q_Read_prist#1...@3.xls
>> Q_Read_prist#1...@4.xls   Q_Read_prist#1...@4.xls
>> Q_Read_prist#1...@5.xls   Q_Read_prist#1...@5.xls
>> Q_Read_prist#1...@6.xls   Q_Read_prist#1...@6.xls
>> Q_Read_prist#1...@7.xls   Q_Read_prist#1...@7.xls
>> Q_Read_prist#1...@8.xls   Q_Read_prist#1...@8.xls
>> Q_Read_prist#1...@9.xls   Q_Read_prist#1...@9.xls
>>
>> I tried to order them using order or sort but it doesn' seem to work. I have 
>> had the same issue in matlab but there I have a function to re-define the 
>> order in a "correct" way.
>>
>> Anyone knows of a smart way to sort these guys from 1 to 19 ascending or 
>> descending?
>>
>> Thanks in advance,
>> Mario
>>
>>   [[alternative HTML version deleted]]
>>
>> __
>> R-help@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.
>
> __
> R-help@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.

__
R-help@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.


Re: [R] Ordering in Sankey diagram using R and googleVis

2015-07-23 Thread Angela via R-help
Hi Jim,

I tried it and it while it does make the diagram look more like what I want, 
there are a few categories still out of order.  Thank you for your help!

-Angela


On Thu, 7/23/15, Jim Lemon drjimle...@gmail.com wrote:

 Subject: Re: [R] Ordering in Sankey diagram using R and googleVis

 Cc: r-help mailing list r-help@r-project.org
 Date: Thursday, July 23, 2015, 6:43 AM

 Hi Angela,
 Assuming that your reformatted data is named
 data, have you tried:

 data[order(data$count,data$before,decreasing=TRUE),]

 Jim

 On
 Thu, Jul 23, 2015 at 3:15 AM, Angela via R-help r-help@r-project.org
 wrote:
  Hello,
 
  I am trying to figure out if there is a
 way to order the left side of a Sankey diagram from most
 frequent to least frequent. I am using R version 3.2.1 and
 using googleVis version 0.5.9 for the Sankey. I've tried
 sorting, but that does not work. Is there anyway to force it
 to arrange the left (before) side in decreasing
 frequency? Something I am missing? Does not have to be using
[[elided Yahoo spam]]
 
  -Angela
 
  Example of the data I have, in a csv
 file:
 
  before   
 after
  A    B
  A 
   B
  A    B
  A 
   C
  A    A
  A 
   A
  A    B
  D 
   E
  F    B
  F 
   B
  F    F
  G 
   H
  G    A
 
  I reformat the data in R so it looks like
 this:
 
  before   
 after    count
  A    B    4
  A    C    1
  A 
   A    2
  D    E    1
  F    B    2
  F 
   F    1
  G    H    1
  G    A    1
 
  Then plot using this:
 
 plot( gvisSankey (data, from=before,
 to=after, weight=freq,
 options=list(width=600, height=800,
  
    sankey={iterations: 2})))
 
 
 __
  R-help@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.

__
R-help@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.


Re: [R] Ordering in Sankey diagram using R and googleVis

2015-07-23 Thread Jim Lemon
Hi Angela,
Assuming that your reformatted data is named data, have you tried:

data[order(data$count,data$before,decreasing=TRUE),]

Jim

On Thu, Jul 23, 2015 at 3:15 AM, Angela via R-help r-help@r-project.org wrote:
 Hello,

 I am trying to figure out if there is a way to order the left side of a 
 Sankey diagram from most frequent to least frequent. I am using R version 
 3.2.1 and using googleVis version 0.5.9 for the Sankey. I've tried sorting, 
 but that does not work. Is there anyway to force it to arrange the left 
 (before) side in decreasing frequency? Something I am missing? Does not 
 have to be using googleVis. Thank you!

 -Angela

 Example of the data I have, in a csv file:

 beforeafter
 AB
 AB
 AB
 AC
 AA
 AA
 AB
 DE
 FB
 FB
 FF
 GH
 GA

 I reformat the data in R so it looks like this:

 beforeaftercount
 AB4
 AC1
 AA2
 DE1
 FB2
 FF1
 GH1
 GA1

 Then plot using this:
 plot( gvisSankey (data, from=before, to=after, weight=freq, 
 options=list(width=600, height=800,
 sankey={iterations: 2})))

 __
 R-help@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.

__
R-help@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.


[R] Ordering in Sankey diagram using R and googleVis

2015-07-22 Thread Angela via R-help
Hello,

I am trying to figure out if there is a way to order the left side of a Sankey 
diagram from most frequent to least frequent. I am using R version 3.2.1 and 
using googleVis version 0.5.9 for the Sankey. I've tried sorting, but that does 
not work. Is there anyway to force it to arrange the left (before) side in 
decreasing frequency? Something I am missing? Does not have to be using 
googleVis. Thank you!

-Angela

Example of the data I have, in a csv file:

before    after
A    B
A    B
A    B
A    C
A    A
A    A
A    B
D    E
F    B
F    B
F    F
G    H
G    A

I reformat the data in R so it looks like this:

before    after    count
A    B    4
A    C    1
A    A    2
D    E    1
F    B    2
F    F    1
G    H    1
G    A    1

Then plot using this:
plot( gvisSankey (data, from=before, to=after, weight=freq, 
options=list(width=600, height=800, 
    sankey={iterations: 2})))

__
R-help@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.


Re: [R] ordering a boxplot

2015-03-22 Thread Antonio Silva
Dear Boris,

Thanks very much, have a great week.

Best regards

Antônio Olinto
Fisheries Institute
São Paulo, Brasil



2015-03-21 21:09 GMT-03:00 Boris Steipe boris.ste...@utoronto.ca:

 ... just for completeness - the more concise way: (no need to go through
 names()).

 boxplot(mydata[,order(apply(mydata,2,median))])

 ... or descending
 boxplot(mydata[,order(-apply(mydata,2,median))])




 B.



 On Mar 21, 2015, at 7:04 PM, Boris Steipe boris.ste...@utoronto.ca
 wrote:

  There may be more concise ways to do this - but you are 99% there with
 your approach:
  try:
 
  boxplot(mydata[,names(sort(apply(mydata,2,median)))])
 
  B.
 
 
  On Mar 21, 2015, at 6:49 PM, Antonio Silva aolinto@gmail.com
 wrote:
 
  Thanks Bill and David
 
  Here goes an example
 
  SP1-c(9,6,7,8,5,8,7,5,9,7)
  SP2-c(1,3,4,2,4,2,5,3,2,1)
  SP3-c(4,6,7,5,7,8,7,6,5,4)
  SP4-c(5,4,3,5,2,3,4,3,4,2)
  mydata-data.frame(SP1,SP2,SP3,SP4)
 
 rownames(mydata)-c(ST1,ST2,ST3,ST4,ST5,ST6,ST7,ST8,ST9,ST10)
  mydata
  boxplot(mydata)
 
  Note that this data frame does not have the format Response ~ Group. In
 my
  real matrix I have up to 40 species.
 
  Is there any way to have the species ordered by their median abundance
 (or
  other parameter?)
 
  The desired order is given by names(sort(apply(mydata,2,median)))
 
  Thanks once more,
 
  Antonio Olinto
  Fisheries Institute
  Sao Paulo, Brazil
 
  2015-03-21 15:13 GMT-03:00 William Dunlap wdun...@tibco.com:
 
  You can use the reorder() function to reorder the grouping vector's
  factor levels according to a function of the data in each group.  E.g.,
  compare the following two plots:
 
   d - data.frame(Response=cos(1:15),
 Group=rep(c(A,B,C),c(6,5,4)))
   par(mfrow=c(1,2))
   boxplot(Response ~ Group, data=d)
   boxplot(Response ~ reorder(Group, X=Response, FUN=median), data=d)
 
 
  Bill Dunlap
  TIBCO Software
  wdunlap tibco.com
 
  On Fri, Mar 20, 2015 at 2:20 PM, Antonio Silva aolinto@gmail.com
  wrote:
 
  Hello
 
  I'm using a dataframe (mydata) where row names are sampling points and
  column names are species in a multivariate analysis.
 
  If I write boxplot(mydata) I'll have boxplots for each species
 abundance
  in
  alphabetical order.
 
  How to get the boxes orderer by the median?
 
  Usually for this I write
 
 
 boxplot(value~category,at=rank(tapply(mydata$value,mydata$category,median)))
  but for this to work I need a column for the categories and another
 column
  for the values.
 
  Thanks in advance, best regards.
 
  Antonio Olinto
 
[[alternative HTML version deleted]]
 
  __
  R-help@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.
 
 
 
 
   [[alternative HTML version deleted]]
 
  __
  R-help@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.
 
  __
  R-help@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.



[[alternative HTML version deleted]]

__
R-help@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.

Re: [R] ordering a boxplot

2015-03-21 Thread David Winsemius

On Mar 20, 2015, at 2:20 PM, Antonio Silva wrote:

 Hello
 
 I'm using a dataframe (mydata) where row names are sampling points and
 column names are species in a multivariate analysis.
 
 If I write boxplot(mydata) I'll have boxplots for each species abundance in
 alphabetical order.
 
 How to get the boxes orderer by the median?
 
 Usually for this I write
 boxplot(value~category,at=rank(tapply(mydata$value,mydata$category,median)))

I would not have expected that to succeed. The usual approach is to change the 
order of factor levels before the call to boxplot.


 but for this to work I need a column for the categories and another column
 for the values.

Yes. That is the usual situation. Since you provide no data we cannot tell what 
is different about your case.

 
 Thanks in advance, best regards.
 
 Antonio Olinto
 
   [[alternative HTML version deleted]]
 
 __
 R-help@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.

David Winsemius
Alameda, CA, USA

__
R-help@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.


Re: [R] ordering a boxplot

2015-03-21 Thread William Dunlap
You can use the reorder() function to reorder the grouping vector's
factor levels according to a function of the data in each group.  E.g.,
compare the following two plots:

   d - data.frame(Response=cos(1:15), Group=rep(c(A,B,C),c(6,5,4)))
   par(mfrow=c(1,2))
   boxplot(Response ~ Group, data=d)
   boxplot(Response ~ reorder(Group, X=Response, FUN=median), data=d)


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Fri, Mar 20, 2015 at 2:20 PM, Antonio Silva aolinto@gmail.com
wrote:

 Hello

 I'm using a dataframe (mydata) where row names are sampling points and
 column names are species in a multivariate analysis.

 If I write boxplot(mydata) I'll have boxplots for each species abundance in
 alphabetical order.

 How to get the boxes orderer by the median?

 Usually for this I write

 boxplot(value~category,at=rank(tapply(mydata$value,mydata$category,median)))
 but for this to work I need a column for the categories and another column
 for the values.

 Thanks in advance, best regards.

 Antonio Olinto

 [[alternative HTML version deleted]]

 __
 R-help@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.


[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] ordering a boxplot

2015-03-21 Thread Antonio Silva
Thanks Bill and David

Here goes an example

SP1-c(9,6,7,8,5,8,7,5,9,7)
SP2-c(1,3,4,2,4,2,5,3,2,1)
SP3-c(4,6,7,5,7,8,7,6,5,4)
SP4-c(5,4,3,5,2,3,4,3,4,2)
mydata-data.frame(SP1,SP2,SP3,SP4)
rownames(mydata)-c(ST1,ST2,ST3,ST4,ST5,ST6,ST7,ST8,ST9,ST10)
mydata
boxplot(mydata)

Note that this data frame does not have the format Response ~ Group. In my
real matrix I have up to 40 species.

Is there any way to have the species ordered by their median abundance (or
other parameter?)

The desired order is given by names(sort(apply(mydata,2,median)))

Thanks once more,

Antonio Olinto
Fisheries Institute
Sao Paulo, Brazil

2015-03-21 15:13 GMT-03:00 William Dunlap wdun...@tibco.com:

 You can use the reorder() function to reorder the grouping vector's
 factor levels according to a function of the data in each group.  E.g.,
 compare the following two plots:

d - data.frame(Response=cos(1:15), Group=rep(c(A,B,C),c(6,5,4)))
par(mfrow=c(1,2))
boxplot(Response ~ Group, data=d)
boxplot(Response ~ reorder(Group, X=Response, FUN=median), data=d)


 Bill Dunlap
 TIBCO Software
 wdunlap tibco.com

 On Fri, Mar 20, 2015 at 2:20 PM, Antonio Silva aolinto@gmail.com
 wrote:

 Hello

 I'm using a dataframe (mydata) where row names are sampling points and
 column names are species in a multivariate analysis.

 If I write boxplot(mydata) I'll have boxplots for each species abundance
 in
 alphabetical order.

 How to get the boxes orderer by the median?

 Usually for this I write

 boxplot(value~category,at=rank(tapply(mydata$value,mydata$category,median)))
 but for this to work I need a column for the categories and another column
 for the values.

 Thanks in advance, best regards.

 Antonio Olinto

 [[alternative HTML version deleted]]

 __
 R-help@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.




[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] ordering a boxplot

2015-03-21 Thread Boris Steipe
There may be more concise ways to do this - but you are 99% there with your 
approach:
try:

boxplot(mydata[,names(sort(apply(mydata,2,median)))])

B.


On Mar 21, 2015, at 6:49 PM, Antonio Silva aolinto@gmail.com wrote:

 Thanks Bill and David
 
 Here goes an example
 
 SP1-c(9,6,7,8,5,8,7,5,9,7)
 SP2-c(1,3,4,2,4,2,5,3,2,1)
 SP3-c(4,6,7,5,7,8,7,6,5,4)
 SP4-c(5,4,3,5,2,3,4,3,4,2)
 mydata-data.frame(SP1,SP2,SP3,SP4)
 rownames(mydata)-c(ST1,ST2,ST3,ST4,ST5,ST6,ST7,ST8,ST9,ST10)
 mydata
 boxplot(mydata)
 
 Note that this data frame does not have the format Response ~ Group. In my
 real matrix I have up to 40 species.
 
 Is there any way to have the species ordered by their median abundance (or
 other parameter?)
 
 The desired order is given by names(sort(apply(mydata,2,median)))
 
 Thanks once more,
 
 Antonio Olinto
 Fisheries Institute
 Sao Paulo, Brazil
 
 2015-03-21 15:13 GMT-03:00 William Dunlap wdun...@tibco.com:
 
 You can use the reorder() function to reorder the grouping vector's
 factor levels according to a function of the data in each group.  E.g.,
 compare the following two plots:
 
   d - data.frame(Response=cos(1:15), Group=rep(c(A,B,C),c(6,5,4)))
   par(mfrow=c(1,2))
   boxplot(Response ~ Group, data=d)
   boxplot(Response ~ reorder(Group, X=Response, FUN=median), data=d)
 
 
 Bill Dunlap
 TIBCO Software
 wdunlap tibco.com
 
 On Fri, Mar 20, 2015 at 2:20 PM, Antonio Silva aolinto@gmail.com
 wrote:
 
 Hello
 
 I'm using a dataframe (mydata) where row names are sampling points and
 column names are species in a multivariate analysis.
 
 If I write boxplot(mydata) I'll have boxplots for each species abundance
 in
 alphabetical order.
 
 How to get the boxes orderer by the median?
 
 Usually for this I write
 
 boxplot(value~category,at=rank(tapply(mydata$value,mydata$category,median)))
 but for this to work I need a column for the categories and another column
 for the values.
 
 Thanks in advance, best regards.
 
 Antonio Olinto
 
[[alternative HTML version deleted]]
 
 __
 R-help@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.
 
 
 
 
   [[alternative HTML version deleted]]
 
 __
 R-help@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.

__
R-help@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.


Re: [R] ordering a boxplot

2015-03-21 Thread Boris Steipe
... just for completeness - the more concise way: (no need to go through 
names()).

boxplot(mydata[,order(apply(mydata,2,median))])

... or descending
boxplot(mydata[,order(-apply(mydata,2,median))])




B.



On Mar 21, 2015, at 7:04 PM, Boris Steipe boris.ste...@utoronto.ca wrote:

 There may be more concise ways to do this - but you are 99% there with your 
 approach:
 try:
 
 boxplot(mydata[,names(sort(apply(mydata,2,median)))])
 
 B.
 
 
 On Mar 21, 2015, at 6:49 PM, Antonio Silva aolinto@gmail.com wrote:
 
 Thanks Bill and David
 
 Here goes an example
 
 SP1-c(9,6,7,8,5,8,7,5,9,7)
 SP2-c(1,3,4,2,4,2,5,3,2,1)
 SP3-c(4,6,7,5,7,8,7,6,5,4)
 SP4-c(5,4,3,5,2,3,4,3,4,2)
 mydata-data.frame(SP1,SP2,SP3,SP4)
 rownames(mydata)-c(ST1,ST2,ST3,ST4,ST5,ST6,ST7,ST8,ST9,ST10)
 mydata
 boxplot(mydata)
 
 Note that this data frame does not have the format Response ~ Group. In my
 real matrix I have up to 40 species.
 
 Is there any way to have the species ordered by their median abundance (or
 other parameter?)
 
 The desired order is given by names(sort(apply(mydata,2,median)))
 
 Thanks once more,
 
 Antonio Olinto
 Fisheries Institute
 Sao Paulo, Brazil
 
 2015-03-21 15:13 GMT-03:00 William Dunlap wdun...@tibco.com:
 
 You can use the reorder() function to reorder the grouping vector's
 factor levels according to a function of the data in each group.  E.g.,
 compare the following two plots:
 
  d - data.frame(Response=cos(1:15), Group=rep(c(A,B,C),c(6,5,4)))
  par(mfrow=c(1,2))
  boxplot(Response ~ Group, data=d)
  boxplot(Response ~ reorder(Group, X=Response, FUN=median), data=d)
 
 
 Bill Dunlap
 TIBCO Software
 wdunlap tibco.com
 
 On Fri, Mar 20, 2015 at 2:20 PM, Antonio Silva aolinto@gmail.com
 wrote:
 
 Hello
 
 I'm using a dataframe (mydata) where row names are sampling points and
 column names are species in a multivariate analysis.
 
 If I write boxplot(mydata) I'll have boxplots for each species abundance
 in
 alphabetical order.
 
 How to get the boxes orderer by the median?
 
 Usually for this I write
 
 boxplot(value~category,at=rank(tapply(mydata$value,mydata$category,median)))
 but for this to work I need a column for the categories and another column
 for the values.
 
 Thanks in advance, best regards.
 
 Antonio Olinto
 
   [[alternative HTML version deleted]]
 
 __
 R-help@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.
 
 
 
 
  [[alternative HTML version deleted]]
 
 __
 R-help@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.
 
 __
 R-help@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.

__
R-help@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.


[R] ordering a boxplot

2015-03-20 Thread Antonio Silva
Hello

I'm using a dataframe (mydata) where row names are sampling points and
column names are species in a multivariate analysis.

If I write boxplot(mydata) I'll have boxplots for each species abundance in
alphabetical order.

How to get the boxes orderer by the median?

Usually for this I write
boxplot(value~category,at=rank(tapply(mydata$value,mydata$category,median)))
but for this to work I need a column for the categories and another column
for the values.

Thanks in advance, best regards.

Antonio Olinto

[[alternative HTML version deleted]]

__
R-help@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.


[R] Ordering the rows of a data frame

2014-01-03 Thread Stefano Sofia

Dear R users,
I have two files of seasonal rainfall data (more than 10,000 rows each); here 
the first 8 rows of each file are reported.

Code_Raingouge,Y_init,M_init,D_init,h_init,m_init,Y_fin,M_fin,D_fin,h_fin,m_fin,Rainfall,N_Values,Quality_Level,Code_Station
2000,1952,12,1,0,0,1953,3,1,0,0,307.20,90,100.0,1510
2000,1953,3,1,0,0,1953,6,1,0,0,153.60,92,100.0,1510
2000,1953,6,1,0,0,1953,9,1,0,0,181.00,92,100.0,1510
2000,1953,9,1,0,0,1953,12,1,0,0,202.40,91,100.0,1510
2000,1953,12,1,0,0,1954,3,1,0,0,153.80,90,100.0,1510
2000,1954,3,1,0,0,1954,6,1,0,0,286.20,92,100.0,1510
2000,1954,6,1,0,0,1954,9,1,0,0,142.80,92,100.0,1510
2000,1954,9,1,0,0,1954,12,1,0,0,186.60,91,100.0,1510
...

Code_Raingouge,Y_init,M_init,D_init,h_init,m_init,Y_fin,M_fin,D_fin,h_fin,m_fin,Rainfall,N_Values,Quality_Level,Code_Station
1056,2004,12,1,0,0,2005,3,1,0,0,93.60,2833,32.8,15
1056,2005,3,1,0,0,2005,6,1,0,0,149.80,4406,49.9,15
1056,2005,6,1,0,0,2005,9,1,0,0,52.80,1440,16.3,15
1056,2005,9,1,0,0,2005,12,1,0,0,191.80,1201,13.7,15
1056,2005,12,1,0,0,2006,3,1,0,0,26.40,336,3.9,15
1056,2006,12,1,0,0,2007,3,1,0,0,59.00,3604,41.7,15
1056,2007,3,1,0,0,2007,6,1,0,0,181.16,4414,50.0,15
1056,2007,6,1,0,0,2007,9,1,0,0,96.00,7337,83.1,15
...

I have to load them as data frames, to merge them and sort them by 
(Y_init,M_init,D_init,Code_Raingouge).

I wrote a short function where I first load the two files as data frames

df_1 - read.csv(file=prec_all_19521201_19821201.csv, sep=,)
df_2 - read.csv(file=prec_all_19821201_20111201.csv, sep=,)

then I merge them by

df_final - merge(df_1, df_2, all=TRUE)

and finally I try to order df_final through

df_final - df_final[order(Y_init, M_init, D_init, Code_Raingouge), ]

but this returns only the first row.

I read the manual carefully and I saw some examples, but I have not been able 
to do this simple task.
I spent quite a long time and now I decided to ask the list.
Could please somebody help me to show me where the mistake is?

Thank you
Stefano




AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere 
informazioni confidenziali, pertanto è destinato solo a persone autorizzate 
alla ricezione. I messaggi di posta elettronica per i client di Regione Marche 
possono contenere informazioni confidenziali e con privilegi legali. Se non si 
è il destinatario specificato, non leggere, copiare, inoltrare o archiviare 
questo messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo al 
mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi 
dell’art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessità ed 
urgenza, la risposta al presente messaggio di posta elettronica può essere 
visionata da persone estranee al destinatario.
IMPORTANT NOTICE: This e-mail message is intended to be received only by 
persons entitled to receive the confidential information it may contain. E-mail 
messages to clients of Regione Marche may contain information that is 
confidential and legally privileged. Please do not read, copy, forward, or 
store this message unless you are an intended recipient of it. If you have 
received this message in error, please forward it to the sender and delete it 
completely from your computer system.

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Ordering the rows of a data frame

2014-01-03 Thread Ista Zahn
On Fri, Jan 3, 2014 at 9:41 AM, Stefano Sofia
stefano.so...@regione.marche.it wrote:

 Dear R users,
 I have two files of seasonal rainfall data (more than 10,000 rows each); here 
 the first 8 rows of each file are reported.

 Code_Raingouge,Y_init,M_init,D_init,h_init,m_init,Y_fin,M_fin,D_fin,h_fin,m_fin,Rainfall,N_Values,Quality_Level,Code_Station
 2000,1952,12,1,0,0,1953,3,1,0,0,307.20,90,100.0,1510
 2000,1953,3,1,0,0,1953,6,1,0,0,153.60,92,100.0,1510
 2000,1953,6,1,0,0,1953,9,1,0,0,181.00,92,100.0,1510
 2000,1953,9,1,0,0,1953,12,1,0,0,202.40,91,100.0,1510
 2000,1953,12,1,0,0,1954,3,1,0,0,153.80,90,100.0,1510
 2000,1954,3,1,0,0,1954,6,1,0,0,286.20,92,100.0,1510
 2000,1954,6,1,0,0,1954,9,1,0,0,142.80,92,100.0,1510
 2000,1954,9,1,0,0,1954,12,1,0,0,186.60,91,100.0,1510
 ...

 Code_Raingouge,Y_init,M_init,D_init,h_init,m_init,Y_fin,M_fin,D_fin,h_fin,m_fin,Rainfall,N_Values,Quality_Level,Code_Station
 1056,2004,12,1,0,0,2005,3,1,0,0,93.60,2833,32.8,15
 1056,2005,3,1,0,0,2005,6,1,0,0,149.80,4406,49.9,15
 1056,2005,6,1,0,0,2005,9,1,0,0,52.80,1440,16.3,15
 1056,2005,9,1,0,0,2005,12,1,0,0,191.80,1201,13.7,15
 1056,2005,12,1,0,0,2006,3,1,0,0,26.40,336,3.9,15
 1056,2006,12,1,0,0,2007,3,1,0,0,59.00,3604,41.7,15
 1056,2007,3,1,0,0,2007,6,1,0,0,181.16,4414,50.0,15
 1056,2007,6,1,0,0,2007,9,1,0,0,96.00,7337,83.1,15
 ...

 I have to load them as data frames, to merge them and sort them by 
 (Y_init,M_init,D_init,Code_Raingouge).

 I wrote a short function where I first load the two files as data frames

 df_1 - read.csv(file=prec_all_19521201_19821201.csv, sep=,)
 df_2 - read.csv(file=prec_all_19821201_20111201.csv, sep=,)

 then I merge them by

 df_final - merge(df_1, df_2, all=TRUE)

 and finally I try to order df_final through

 df_final - df_final[order(Y_init, M_init, D_init, Code_Raingouge), ]

You probably need

df_final - df_final[order(df_final$Y_init, df_final$M_init,
df_final$D_init, df_final$Code_Raingouge), ]

or

df_final - df_final[with(df_final, order(Y_init, M_init, D_init,
Code_Raingouge)), ]


 but this returns only the first row.

That is strange; do you have copies of Y_init, M_init etc. in your workspace?


 I read the manual carefully and I saw some examples, but I have not been able 
 to do this simple task.

I can see how the data.frame sorting examples in  ?order would lead to
this confusion, as they are limited to the special case where the
variables you want to sort by are in the workspace rather than (as is
more often the case) variables in the data.frame itself.

 I spent quite a long time and now I decided to ask the list.
 Could please somebody help me to show me where the mistake is?

 Thank you
 Stefano


 

 AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere 
 informazioni confidenziali, pertanto è destinato solo a persone autorizzate 
 alla ricezione. I messaggi di posta elettronica per i client di Regione 
 Marche possono contenere informazioni confidenziali e con privilegi legali. 
 Se non si è il destinatario specificato, non leggere, copiare, inoltrare o 
 archiviare questo messaggio. Se si è ricevuto questo messaggio per errore, 
 inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio 
 computer. Ai sensi dell’art. 6 della DGR n. 1394/2008 si segnala che, in caso 
 di necessità ed urgenza, la risposta al presente messaggio di posta 
 elettronica può essere visionata da persone estranee al destinatario.
 IMPORTANT NOTICE: This e-mail message is intended to be received only by 
 persons entitled to receive the confidential information it may contain. 
 E-mail messages to clients of Regione Marche may contain information that is 
 confidential and legally privileged. Please do not read, copy, forward, or 
 store this message unless you are an intended recipient of it. If you have 
 received this message in error, please forward it to the sender and delete it 
 completely from your computer system.

 [[alternative HTML version deleted]]


 __
 R-help@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.


__
R-help@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.


Re: [R] Ordering the rows of a data frame

2014-01-03 Thread Dmitry Pavlyuk
Hi Sofia!

You need to attach the data file before sorting:

attach(df_final)

or just use full qualified names (like df_final$Y_init)

Dmitry

On 03/01/2014 16:41, Stefano Sofia wrote:
 Dear R users,
 I have two files of seasonal rainfall data (more than 10,000 rows each); here 
 the first 8 rows of each file are reported.

 Code_Raingouge,Y_init,M_init,D_init,h_init,m_init,Y_fin,M_fin,D_fin,h_fin,m_fin,Rainfall,N_Values,Quality_Level,Code_Station
 2000,1952,12,1,0,0,1953,3,1,0,0,307.20,90,100.0,1510
 2000,1953,3,1,0,0,1953,6,1,0,0,153.60,92,100.0,1510
 2000,1953,6,1,0,0,1953,9,1,0,0,181.00,92,100.0,1510
 2000,1953,9,1,0,0,1953,12,1,0,0,202.40,91,100.0,1510
 2000,1953,12,1,0,0,1954,3,1,0,0,153.80,90,100.0,1510
 2000,1954,3,1,0,0,1954,6,1,0,0,286.20,92,100.0,1510
 2000,1954,6,1,0,0,1954,9,1,0,0,142.80,92,100.0,1510
 2000,1954,9,1,0,0,1954,12,1,0,0,186.60,91,100.0,1510
 ...

 Code_Raingouge,Y_init,M_init,D_init,h_init,m_init,Y_fin,M_fin,D_fin,h_fin,m_fin,Rainfall,N_Values,Quality_Level,Code_Station
 1056,2004,12,1,0,0,2005,3,1,0,0,93.60,2833,32.8,15
 1056,2005,3,1,0,0,2005,6,1,0,0,149.80,4406,49.9,15
 1056,2005,6,1,0,0,2005,9,1,0,0,52.80,1440,16.3,15
 1056,2005,9,1,0,0,2005,12,1,0,0,191.80,1201,13.7,15
 1056,2005,12,1,0,0,2006,3,1,0,0,26.40,336,3.9,15
 1056,2006,12,1,0,0,2007,3,1,0,0,59.00,3604,41.7,15
 1056,2007,3,1,0,0,2007,6,1,0,0,181.16,4414,50.0,15
 1056,2007,6,1,0,0,2007,9,1,0,0,96.00,7337,83.1,15
 ...

 I have to load them as data frames, to merge them and sort them by 
 (Y_init,M_init,D_init,Code_Raingouge).

 I wrote a short function where I first load the two files as data frames

 df_1 - read.csv(file=prec_all_19521201_19821201.csv, sep=,)
 df_2 - read.csv(file=prec_all_19821201_20111201.csv, sep=,)

 then I merge them by

 df_final - merge(df_1, df_2, all=TRUE)

 and finally I try to order df_final through

 df_final - df_final[order(Y_init, M_init, D_init, Code_Raingouge), ]

 but this returns only the first row.

 I read the manual carefully and I saw some examples, but I have not been able 
 to do this simple task.
 I spent quite a long time and now I decided to ask the list.
 Could please somebody help me to show me where the mistake is?

 Thank you
 Stefano


 

 AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere 
 informazioni confidenziali, pertanto è destinato solo a persone autorizzate 
 alla ricezione. I messaggi di posta elettronica per i client di Regione 
 Marche possono contenere informazioni confidenziali e con privilegi legali. 
 Se non si è il destinatario specificato, non leggere, copiare, inoltrare o 
 archiviare questo messaggio. Se si è ricevuto questo messaggio per errore, 
 inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio 
 computer. Ai sensi dellâEUR^(TM)art. 6 della DGR n. 1394/2008 si segnala che, 
 in caso di necessità ed urgenza, la risposta al presente messaggio di posta 
 elettronica può essere visionata da persone estranee al destinatario.
 IMPORTANT NOTICE: This e-mail message is intended to be received only by 
 persons entitled to receive the confidential information it may contain. 
 E-mail messages to clients of Regione Marche may contain information that is 
 confidential and legally privileged. Please do not read, copy, forward, or 
 store this message unless you are an intended recipient of it. If you have 
 received this message in error, please forward it to the sender and delete it 
 completely from your computer system.

   [[alternative HTML version deleted]]



 __
 R-help@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.


[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Ordering the rows of a data frame

2014-01-03 Thread Bert Gunter
Inline

Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374

Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom.
H. Gilbert Welch




On Fri, Jan 3, 2014 at 7:08 AM, Dmitry Pavlyuk
dmitry.v.pavl...@gmail.com wrote:
 Hi Sofia!

 You need to attach the data file before sorting:

This is false! -- and generally a bad idea.  See ?with
Please do not give advice without checking whether it is correct.

-- Bert



 attach(df_final)

 or just use full qualified names (like df_final$Y_init)

 Dmitry

 On 03/01/2014 16:41, Stefano Sofia wrote:
 Dear R users,
 I have two files of seasonal rainfall data (more than 10,000 rows each); 
 here the first 8 rows of each file are reported.

 Code_Raingouge,Y_init,M_init,D_init,h_init,m_init,Y_fin,M_fin,D_fin,h_fin,m_fin,Rainfall,N_Values,Quality_Level,Code_Station
 2000,1952,12,1,0,0,1953,3,1,0,0,307.20,90,100.0,1510
 2000,1953,3,1,0,0,1953,6,1,0,0,153.60,92,100.0,1510
 2000,1953,6,1,0,0,1953,9,1,0,0,181.00,92,100.0,1510
 2000,1953,9,1,0,0,1953,12,1,0,0,202.40,91,100.0,1510
 2000,1953,12,1,0,0,1954,3,1,0,0,153.80,90,100.0,1510
 2000,1954,3,1,0,0,1954,6,1,0,0,286.20,92,100.0,1510
 2000,1954,6,1,0,0,1954,9,1,0,0,142.80,92,100.0,1510
 2000,1954,9,1,0,0,1954,12,1,0,0,186.60,91,100.0,1510
 ...

 Code_Raingouge,Y_init,M_init,D_init,h_init,m_init,Y_fin,M_fin,D_fin,h_fin,m_fin,Rainfall,N_Values,Quality_Level,Code_Station
 1056,2004,12,1,0,0,2005,3,1,0,0,93.60,2833,32.8,15
 1056,2005,3,1,0,0,2005,6,1,0,0,149.80,4406,49.9,15
 1056,2005,6,1,0,0,2005,9,1,0,0,52.80,1440,16.3,15
 1056,2005,9,1,0,0,2005,12,1,0,0,191.80,1201,13.7,15
 1056,2005,12,1,0,0,2006,3,1,0,0,26.40,336,3.9,15
 1056,2006,12,1,0,0,2007,3,1,0,0,59.00,3604,41.7,15
 1056,2007,3,1,0,0,2007,6,1,0,0,181.16,4414,50.0,15
 1056,2007,6,1,0,0,2007,9,1,0,0,96.00,7337,83.1,15
 ...

 I have to load them as data frames, to merge them and sort them by 
 (Y_init,M_init,D_init,Code_Raingouge).

 I wrote a short function where I first load the two files as data frames

 df_1 - read.csv(file=prec_all_19521201_19821201.csv, sep=,)
 df_2 - read.csv(file=prec_all_19821201_20111201.csv, sep=,)

 then I merge them by

 df_final - merge(df_1, df_2, all=TRUE)

 and finally I try to order df_final through

 df_final - df_final[order(Y_init, M_init, D_init, Code_Raingouge), ]

 but this returns only the first row.

 I read the manual carefully and I saw some examples, but I have not been 
 able to do this simple task.
 I spent quite a long time and now I decided to ask the list.
 Could please somebody help me to show me where the mistake is?

 Thank you
 Stefano


 

 AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere 
 informazioni confidenziali, pertanto è destinato solo a persone autorizzate 
 alla ricezione. I messaggi di posta elettronica per i client di Regione 
 Marche possono contenere informazioni confidenziali e con privilegi legali. 
 Se non si è il destinatario specificato, non leggere, copiare, inoltrare o 
 archiviare questo messaggio. Se si è ricevuto questo messaggio per errore, 
 inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio 
 computer. Ai sensi dellâEUR^(TM)art. 6 della DGR n. 1394/2008 si segnala 
 che, in caso di necessità ed urgenza, la risposta al presente messaggio di 
 posta elettronica può essere visionata da persone estranee al destinatario.
 IMPORTANT NOTICE: This e-mail message is intended to be received only by 
 persons entitled to receive the confidential information it may contain. 
 E-mail messages to clients of Regione Marche may contain information that is 
 confidential and legally privileged. Please do not read, copy, forward, or 
 store this message unless you are an intended recipient of it. If you have 
 received this message in error, please forward it to the sender and delete 
 it completely from your computer system.

   [[alternative HTML version deleted]]



 __
 R-help@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.


 [[alternative HTML version deleted]]


 __
 R-help@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.


__
R-help@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.


Re: [R] Ordering the rows of a data frame

2014-01-03 Thread Dmitry Pavlyuk
Bert, why do you think that attach is not working in this case? Did 
you check it before your advice? :)
I agree about generally bad approach, but it is quite convenient for 
work with one data set.


Dmitry

On 03/01/2014 18:28, Bert Gunter wrote:

Inline

Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374

Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom.
H. Gilbert Welch




On Fri, Jan 3, 2014 at 7:08 AM, Dmitry Pavlyuk
dmitry.v.pavl...@gmail.com wrote:

Hi Sofia!

You need to attach the data file before sorting:

This is false! -- and generally a bad idea.  See ?with
Please do not give advice without checking whether it is correct.

-- Bert



attach(df_final)

or just use full qualified names (like df_final$Y_init)

Dmitry

On 03/01/2014 16:41, Stefano Sofia wrote:

Dear R users,
I have two files of seasonal rainfall data (more than 10,000 rows each); here 
the first 8 rows of each file are reported.

Code_Raingouge,Y_init,M_init,D_init,h_init,m_init,Y_fin,M_fin,D_fin,h_fin,m_fin,Rainfall,N_Values,Quality_Level,Code_Station
2000,1952,12,1,0,0,1953,3,1,0,0,307.20,90,100.0,1510
2000,1953,3,1,0,0,1953,6,1,0,0,153.60,92,100.0,1510
2000,1953,6,1,0,0,1953,9,1,0,0,181.00,92,100.0,1510
2000,1953,9,1,0,0,1953,12,1,0,0,202.40,91,100.0,1510
2000,1953,12,1,0,0,1954,3,1,0,0,153.80,90,100.0,1510
2000,1954,3,1,0,0,1954,6,1,0,0,286.20,92,100.0,1510
2000,1954,6,1,0,0,1954,9,1,0,0,142.80,92,100.0,1510
2000,1954,9,1,0,0,1954,12,1,0,0,186.60,91,100.0,1510
...

Code_Raingouge,Y_init,M_init,D_init,h_init,m_init,Y_fin,M_fin,D_fin,h_fin,m_fin,Rainfall,N_Values,Quality_Level,Code_Station
1056,2004,12,1,0,0,2005,3,1,0,0,93.60,2833,32.8,15
1056,2005,3,1,0,0,2005,6,1,0,0,149.80,4406,49.9,15
1056,2005,6,1,0,0,2005,9,1,0,0,52.80,1440,16.3,15
1056,2005,9,1,0,0,2005,12,1,0,0,191.80,1201,13.7,15
1056,2005,12,1,0,0,2006,3,1,0,0,26.40,336,3.9,15
1056,2006,12,1,0,0,2007,3,1,0,0,59.00,3604,41.7,15
1056,2007,3,1,0,0,2007,6,1,0,0,181.16,4414,50.0,15
1056,2007,6,1,0,0,2007,9,1,0,0,96.00,7337,83.1,15
...

I have to load them as data frames, to merge them and sort them by 
(Y_init,M_init,D_init,Code_Raingouge).

I wrote a short function where I first load the two files as data frames

df_1 - read.csv(file=prec_all_19521201_19821201.csv, sep=,)
df_2 - read.csv(file=prec_all_19821201_20111201.csv, sep=,)

then I merge them by

df_final - merge(df_1, df_2, all=TRUE)

and finally I try to order df_final through

df_final - df_final[order(Y_init, M_init, D_init, Code_Raingouge), ]

but this returns only the first row.

I read the manual carefully and I saw some examples, but I have not been able 
to do this simple task.
I spent quite a long time and now I decided to ask the list.
Could please somebody help me to show me where the mistake is?

Thank you
Stefano




AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere 
informazioni confidenziali, pertanto è destinato solo a persone autorizzate 
alla ricezione. I messaggi di posta elettronica per i client di Regione Marche 
possono contenere informazioni confidenziali e con privilegi legali. Se non si 
è il destinatario specificato, non leggere, copiare, inoltrare o archiviare 
questo messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo al 
mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi 
dellâEUR^(TM)art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessità 
 ed urgenza, la risposta al presente messaggio di posta elettronica può essere 
visionata da persone estranee al destinatario.
IMPORTANT NOTICE: This e-mail message is intended to be received only by 
persons entitled to receive the confidential information it may contain. E-mail 
messages to clients of Regione Marche may contain information that is 
confidential and legally privileged. Please do not read, copy, forward, or 
store this message unless you are an intended recipient of it. If you have 
received this message in error, please forward it to the sender and delete it 
completely from your computer system.

   [[alternative HTML version deleted]]



__
R-help@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.


 [[alternative HTML version deleted]]


__
R-help@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.



__
R-help@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, 

Re: [R] Ordering the rows of a data frame

2014-01-03 Thread Bert Gunter
You misunderstand = I was not sufficiently clear.

What is false is your statement that you **need** to attach the data
file before sorting. You do not. with()/within() can be used to avoid
using the fully qualified names without attaching. I did not claim
that attaching first would not work, only that it was not
**necessary** and is generally unwise.


-- Bert



Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374

Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom.
H. Gilbert Welch




On Fri, Jan 3, 2014 at 9:21 AM, Dmitry Pavlyuk
dmitry.v.pavl...@gmail.com wrote:
 Bert, why do you think that attach is not working in this case? Did you
 check it before your advice? :)
 I agree about generally bad approach, but it is quite convenient for work
 with one data set.

 Dmitry

 On 03/01/2014 18:28, Bert Gunter wrote:

 Inline

 Bert Gunter
 Genentech Nonclinical Biostatistics
 (650) 467-7374

 Data is not information. Information is not knowledge. And knowledge
 is certainly not wisdom.
 H. Gilbert Welch




 On Fri, Jan 3, 2014 at 7:08 AM, Dmitry Pavlyuk
 dmitry.v.pavl...@gmail.com wrote:

 Hi Sofia!

 You need to attach the data file before sorting:

 This is false! -- and generally a bad idea.  See ?with
 Please do not give advice without checking whether it is correct.

 -- Bert


 attach(df_final)

 or just use full qualified names (like df_final$Y_init)

 Dmitry

 On 03/01/2014 16:41, Stefano Sofia wrote:

 Dear R users,
 I have two files of seasonal rainfall data (more than 10,000 rows each);
 here the first 8 rows of each file are reported.


 Code_Raingouge,Y_init,M_init,D_init,h_init,m_init,Y_fin,M_fin,D_fin,h_fin,m_fin,Rainfall,N_Values,Quality_Level,Code_Station
 2000,1952,12,1,0,0,1953,3,1,0,0,307.20,90,100.0,1510
 2000,1953,3,1,0,0,1953,6,1,0,0,153.60,92,100.0,1510
 2000,1953,6,1,0,0,1953,9,1,0,0,181.00,92,100.0,1510
 2000,1953,9,1,0,0,1953,12,1,0,0,202.40,91,100.0,1510
 2000,1953,12,1,0,0,1954,3,1,0,0,153.80,90,100.0,1510
 2000,1954,3,1,0,0,1954,6,1,0,0,286.20,92,100.0,1510
 2000,1954,6,1,0,0,1954,9,1,0,0,142.80,92,100.0,1510
 2000,1954,9,1,0,0,1954,12,1,0,0,186.60,91,100.0,1510
 ...


 Code_Raingouge,Y_init,M_init,D_init,h_init,m_init,Y_fin,M_fin,D_fin,h_fin,m_fin,Rainfall,N_Values,Quality_Level,Code_Station
 1056,2004,12,1,0,0,2005,3,1,0,0,93.60,2833,32.8,15
 1056,2005,3,1,0,0,2005,6,1,0,0,149.80,4406,49.9,15
 1056,2005,6,1,0,0,2005,9,1,0,0,52.80,1440,16.3,15
 1056,2005,9,1,0,0,2005,12,1,0,0,191.80,1201,13.7,15
 1056,2005,12,1,0,0,2006,3,1,0,0,26.40,336,3.9,15
 1056,2006,12,1,0,0,2007,3,1,0,0,59.00,3604,41.7,15
 1056,2007,3,1,0,0,2007,6,1,0,0,181.16,4414,50.0,15
 1056,2007,6,1,0,0,2007,9,1,0,0,96.00,7337,83.1,15
 ...

 I have to load them as data frames, to merge them and sort them by
 (Y_init,M_init,D_init,Code_Raingouge).

 I wrote a short function where I first load the two files as data frames

 df_1 - read.csv(file=prec_all_19521201_19821201.csv, sep=,)
 df_2 - read.csv(file=prec_all_19821201_20111201.csv, sep=,)

 then I merge them by

 df_final - merge(df_1, df_2, all=TRUE)

 and finally I try to order df_final through

 df_final - df_final[order(Y_init, M_init, D_init, Code_Raingouge), ]

 but this returns only the first row.

 I read the manual carefully and I saw some examples, but I have not been
 able to do this simple task.
 I spent quite a long time and now I decided to ask the list.
 Could please somebody help me to show me where the mistake is?

 Thank you
 Stefano


 

 AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere
 informazioni confidenziali, pertanto è destinato solo a persone 
 autorizzate
 alla ricezione. I messaggi di posta elettronica per i client di Regione
 Marche possono contenere informazioni confidenziali e con privilegi legali.
 Se non si è il destinatario specificato, non leggere, copiare, inoltrare o
 archiviare questo messaggio. Se si è ricevuto questo messaggio per errore,
 inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio
 computer. Ai sensi dellâEUR^(TM)art. 6 della DGR n. 1394/2008 si segnala
 che, in caso di necessità ed urgenza, la risposta al presente messaggio di
 posta elettronica può essere visionata da persone estranee al 
 destinatario.
 IMPORTANT NOTICE: This e-mail message is intended to be received only by
 persons entitled to receive the confidential information it may contain.
 E-mail messages to clients of Regione Marche may contain information that 
 is
 confidential and legally privileged. Please do not read, copy, forward, or
 store this message unless you are an intended recipient of it. If you have
 received this message in error, please forward it to the sender and delete
 it completely from your computer system.

[[alternative HTML version deleted]]



 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do 

Re: [R] Ordering the rows of a data frame

2014-01-03 Thread Dmitry Pavlyuk

Ah, ok, thank you for explanations!

Dmitry

On 03/01/2014 20:00, Bert Gunter wrote:

You misunderstand = I was not sufficiently clear.

What is false is your statement that you **need** to attach the data
file before sorting. You do not. with()/within() can be used to avoid
using the fully qualified names without attaching. I did not claim
that attaching first would not work, only that it was not
**necessary** and is generally unwise.


-- Bert



Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374

Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom.
H. Gilbert Welch




On Fri, Jan 3, 2014 at 9:21 AM, Dmitry Pavlyuk
dmitry.v.pavl...@gmail.com wrote:

Bert, why do you think that attach is not working in this case? Did you
check it before your advice? :)
I agree about generally bad approach, but it is quite convenient for work
with one data set.

Dmitry

On 03/01/2014 18:28, Bert Gunter wrote:

Inline

Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374

Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom.
H. Gilbert Welch




On Fri, Jan 3, 2014 at 7:08 AM, Dmitry Pavlyuk
dmitry.v.pavl...@gmail.com wrote:

Hi Sofia!

You need to attach the data file before sorting:

This is false! -- and generally a bad idea.  See ?with
Please do not give advice without checking whether it is correct.

-- Bert



attach(df_final)

or just use full qualified names (like df_final$Y_init)

Dmitry

On 03/01/2014 16:41, Stefano Sofia wrote:

Dear R users,
I have two files of seasonal rainfall data (more than 10,000 rows each);
here the first 8 rows of each file are reported.


Code_Raingouge,Y_init,M_init,D_init,h_init,m_init,Y_fin,M_fin,D_fin,h_fin,m_fin,Rainfall,N_Values,Quality_Level,Code_Station
2000,1952,12,1,0,0,1953,3,1,0,0,307.20,90,100.0,1510
2000,1953,3,1,0,0,1953,6,1,0,0,153.60,92,100.0,1510
2000,1953,6,1,0,0,1953,9,1,0,0,181.00,92,100.0,1510
2000,1953,9,1,0,0,1953,12,1,0,0,202.40,91,100.0,1510
2000,1953,12,1,0,0,1954,3,1,0,0,153.80,90,100.0,1510
2000,1954,3,1,0,0,1954,6,1,0,0,286.20,92,100.0,1510
2000,1954,6,1,0,0,1954,9,1,0,0,142.80,92,100.0,1510
2000,1954,9,1,0,0,1954,12,1,0,0,186.60,91,100.0,1510
...


Code_Raingouge,Y_init,M_init,D_init,h_init,m_init,Y_fin,M_fin,D_fin,h_fin,m_fin,Rainfall,N_Values,Quality_Level,Code_Station
1056,2004,12,1,0,0,2005,3,1,0,0,93.60,2833,32.8,15
1056,2005,3,1,0,0,2005,6,1,0,0,149.80,4406,49.9,15
1056,2005,6,1,0,0,2005,9,1,0,0,52.80,1440,16.3,15
1056,2005,9,1,0,0,2005,12,1,0,0,191.80,1201,13.7,15
1056,2005,12,1,0,0,2006,3,1,0,0,26.40,336,3.9,15
1056,2006,12,1,0,0,2007,3,1,0,0,59.00,3604,41.7,15
1056,2007,3,1,0,0,2007,6,1,0,0,181.16,4414,50.0,15
1056,2007,6,1,0,0,2007,9,1,0,0,96.00,7337,83.1,15
...

I have to load them as data frames, to merge them and sort them by
(Y_init,M_init,D_init,Code_Raingouge).

I wrote a short function where I first load the two files as data frames

df_1 - read.csv(file=prec_all_19521201_19821201.csv, sep=,)
df_2 - read.csv(file=prec_all_19821201_20111201.csv, sep=,)

then I merge them by

df_final - merge(df_1, df_2, all=TRUE)

and finally I try to order df_final through

df_final - df_final[order(Y_init, M_init, D_init, Code_Raingouge), ]

but this returns only the first row.

I read the manual carefully and I saw some examples, but I have not been
able to do this simple task.
I spent quite a long time and now I decided to ask the list.
Could please somebody help me to show me where the mistake is?

Thank you
Stefano




AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere
informazioni confidenziali, pertanto è destinato solo a persone autorizzate
alla ricezione. I messaggi di posta elettronica per i client di Regione
Marche possono contenere informazioni confidenziali e con privilegi legali.
Se non si è il destinatario specificato, non leggere, copiare, inoltrare o
archiviare questo messaggio. Se si è ricevuto questo messaggio per errore,
inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio
computer. Ai sensi dellâEUR^(TM)art. 6 della DGR n. 1394/2008 si segnala
che, in caso di necessità ed urgenza, la risposta al presente messaggio di
posta elettronica può essere visionata da persone estranee al destinatario.
IMPORTANT NOTICE: This e-mail message is intended to be received only by
persons entitled to receive the confidential information it may contain.
E-mail messages to clients of Regione Marche may contain information that is
confidential and legally privileged. Please do not read, copy, forward, or
store this message unless you are an intended recipient of it. If you have
received this message in error, please forward it to the sender and delete
it completely from your computer system.

[[alternative HTML version deleted]]



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do 

Re: [R] Ordering a matrix (and not losing the rownames)

2013-09-02 Thread arun
Hi  Ramón,

It is for the column index.
For ex:
tags_totals[order(tags_totals[,1],decreasing=TRUE),1,drop=FALSE] #same as 
previous solution as there is only one column.  
#   [,1]
#Grupos   23
#Wikis    15
#Glosarios    11
#Bases de datos    7
#Taller    5

order(tags_totals[,1],decreasing=TRUE) #creates the row index

#If you don't specify the column index, it will select all the columns.


 tags_totals[1,1] 
#Wikis 
 #  15 
tags_totals[1,1,drop=FALSE] 
#  [,1]
#Wikis   15

tags_totals[1,,drop=FALSE] 
#  [,1]
#Wikis   15


is.matrix(tags_totals[1,1])
#[1] FALSE
is.matrix(tags_totals[1,1,drop=FALSE])
#[1] TRUE



A.K.


Many thanks Arun, 
This is important for me because I will need to do this operation 
many times. However, there is one thing that intrigues me. Why it is 
necessary to put two commas in a row? 

 tags_totals[order(tags_totals[,1],decreasing=TRUE),,drop=FALSE] 
               [,1] 
Grupos           23 
Wikis            15 
Glosarios        11 
Bases de datos    7 
Taller            5 
 tags_totals[order(tags_totals[,1],decreasing=TRUE),drop=FALSE] 
[1] 23 15 11  7  5 

I've been reading around trrying to undestand it, but I can't see the logic. 

Many thanks 


- Original Message -
From: arun smartpink...@yahoo.com
To: R help r-help@r-project.org
Cc: 
Sent: Friday, August 30, 2013 9:27 AM
Subject: Re: Ordering a matrix (and not losing the rownames)

Hi Ramón,
May be this helps:
tags_totals-matrix(c(15,11,23,7,5),ncol=1,dimnames=list(c(Wikis,Glosarios,Grupos,Bases
 de datos,Taller),NULL))

tags_totals[order(tags_totals[,1],decreasing=TRUE),,drop=FALSE]
#   [,1]
#Grupos   23
#Wikis    15
#Glosarios    11
#Bases de datos    7
#Taller    5

A.K.



Hello, 

I have a matrix like this: 

 tags_totals 
               [,1] 
Wikis            15 
Glosarios        11 
Grupos           23 
Bases de datos    7 
Taller            5 

And I want to order by the value of the first column. I do this: 

ordered_matrix - 
as.matrix(tags_totals[order(tags_totals[,1],decreasing=TRUE)]) 

It orders alright, but I lose the rownames, that I need for the graphics 
 ordered_matrix 
     [,1] 
[1,]   23 
[2,]   15 
[3,]   11 
[4,]    7 
[5,]    5 

 rownames(ordered_matrix) 
NULL 

If I try to do it after converting to a dataframe I get an error that I don't 
understand: 

 tags_totals_frame - as.data.frame(tags_totals) 
 tags_totals_frame[,1] 
[1] 15 11 23  7  5 
 ordered_frame - 
 tags_totals_frame[order(tags_totals_frame[,1],decreasing=TRUE)] 
Error en `[.data.frame`(tags_totals_frame, order(tags_totals_frame[, 1],  : 
  undefined columns selected 

Thanks on any help, 

-- 
== 
Ramón Ovelar 
Campus Virtual Birtuala UPV/EHU 
Tel: (34) 94 601 3407 
http://campusvirtual.ehu.es


__
R-help@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.


Re: [R] Ordering a matrix (and not losing the rownames)

2013-08-30 Thread arun
Hi Ramón,
May be this helps:
tags_totals-matrix(c(15,11,23,7,5),ncol=1,dimnames=list(c(Wikis,Glosarios,Grupos,Bases
 de datos,Taller),NULL))

tags_totals[order(tags_totals[,1],decreasing=TRUE),,drop=FALSE]
#   [,1]
#Grupos   23
#Wikis    15
#Glosarios    11
#Bases de datos    7
#Taller    5

A.K.



Hello, 

I have a matrix like this: 

 tags_totals 
               [,1] 
Wikis            15 
Glosarios        11 
Grupos           23 
Bases de datos    7 
Taller            5 

And I want to order by the value of the first column. I do this: 

ordered_matrix - 
as.matrix(tags_totals[order(tags_totals[,1],decreasing=TRUE)]) 

It orders alright, but I lose the rownames, that I need for the graphics 
 ordered_matrix 
     [,1] 
[1,]   23 
[2,]   15 
[3,]   11 
[4,]    7 
[5,]    5 

 rownames(ordered_matrix) 
NULL 

If I try to do it after converting to a dataframe I get an error that I don't 
understand: 

 tags_totals_frame - as.data.frame(tags_totals) 
 tags_totals_frame[,1] 
[1] 15 11 23  7  5 
 ordered_frame - 
 tags_totals_frame[order(tags_totals_frame[,1],decreasing=TRUE)] 
Error en `[.data.frame`(tags_totals_frame, order(tags_totals_frame[, 1],  : 
  undefined columns selected 

Thanks on any help, 

-- 
== 
Ramón Ovelar 
Campus Virtual Birtuala UPV/EHU 
Tel: (34) 94 601 3407 
http://campusvirtual.ehu.es


__
R-help@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.


Re: [R] Ordering a matrix by row value in R2.15

2013-03-24 Thread Pete Brecknock
fitz_ra wrote
 I know this is posted a lot, I've been through about 40 messages reading
 how to do this so let me apologize in advance because I can't get this
 operation to work unlike the many examples shown.
 
 I have a 2 row matrix 
 temp
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
 [,9][,10]
 [1,] 17.000 9.00 26.0  5.0 23.0 21.0 19.0 17.0
 10.0  63.
 [2,] 15.554 7.793718 33.29079 15.53094 20.44825 14.34443 11.83552 11.62997
 10.16019 115.2602
 
 I want to order the matrix using the second row in ascending order.  From
 the many examples (usually applied to columns) the typical solution
 appears to be: 
 temp[order(temp[2,]),]
 Error: subscript out of bounds
 
 However as you can see I get an error here.
 
 When I run this one line command:
 sort(temp[2,])
  [1]   7.793718  10.160190  11.629973  11.835520  14.344426  15.530939 
 15.553999  20.448249  33.290789
 [10] 115.260192
 
 This works but I want the matrix to update and the corresponding values of
 row 1 to switch with the sort.

Maybe consider the order function 

orig - matrix(c(10,20,30,3,1,2), nrow=2, byrow=TRUE)

new -t(apply(orig,1,function(x) x[order(orig[2,])]))

 orig
 [,1] [,2] [,3]
[1,]   10   20   30
[2,]312
 new
 [,1] [,2] [,3]
[1,]   20   30   10
[2,]123

HTH 

Pete




--
View this message in context: 
http://r.789695.n4.nabble.com/Ordering-a-matrix-by-row-value-in-R2-15-tp4662337p4662340.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Ordering a matrix by row value in R2.15

2013-03-24 Thread soon yi
or this with Pete's example

orig[,order(orig[2,])]





Pete Brecknock wrote
 
 fitz_ra wrote
 I know this is posted a lot, I've been through about 40 messages reading
 how to do this so let me apologize in advance because I can't get this
 operation to work unlike the many examples shown.
 
 I have a 2 row matrix 
 temp
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
 [,8] [,9][,10]
 [1,] 17.000 9.00 26.0  5.0 23.0 21.0 19.0
 17.0 10.0  63.
 [2,] 15.554 7.793718 33.29079 15.53094 20.44825 14.34443 11.83552
 11.62997 10.16019 115.2602
 
 I want to order the matrix using the second row in ascending order.  From
 the many examples (usually applied to columns) the typical solution
 appears to be: 
 temp[order(temp[2,]),]
 Error: subscript out of bounds
 
 However as you can see I get an error here.
 
 When I run this one line command:
 sort(temp[2,])
  [1]   7.793718  10.160190  11.629973  11.835520  14.344426  15.530939 
 15.553999  20.448249  33.290789
 [10] 115.260192
 
 This works but I want the matrix to update and the corresponding values
 of row 1 to switch with the sort.
 Maybe consider the order function 
 
 orig - matrix(c(10,20,30,3,1,2), nrow=2, byrow=TRUE)
 
 new -t(apply(orig,1,function(x) x[order(orig[2,])]))
 
 orig
  [,1] [,2] [,3]
 [1,]   10   20   30
 [2,]312
 new
  [,1] [,2] [,3]
 [1,]   20   30   10
 [2,]123
 
 HTH 
 
 Pete





--
View this message in context: 
http://r.789695.n4.nabble.com/Ordering-a-matrix-by-row-value-in-R2-15-tp4662337p4662342.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Ordering a matrix by row value in R2.15

2013-03-24 Thread William Dunlap
fitz_ra no address
  I want to order the matrix using the second row in ascending order.  From
  the many examples (usually applied to columns) the typical solution
  appears to be:
  temp[order(temp[2,]),]
  Error: subscript out of bounds

That tries to reorder the rows of temp according the values in its second
row, which causes the error (unless you are unlucky and have more rows than
columns, in which case you silently get a wrong answer).  You want to reorder
the columns of temp, so make the output of order() the column (second)
argument to [,]:

   temp[, order(temp[2,])]
   [,1] [,2] [,3] [,4] [,5] [,6]   [,7] [,8]
  [1,] 9.00 10.0 17.0 19.0 21.0  5.0 17.000 23.0
  [2,] 7.793718 10.16019 11.62997 11.83552 14.34443 15.53094 15.554 20.44825
   [,9][,10]
  [1,] 26.0  63.
  [2,] 33.29079 115.2602

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf
 Of Pete Brecknock
 Sent: Sunday, March 24, 2013 5:12 PM
 To: r-help@r-project.org
 Subject: Re: [R] Ordering a matrix by row value in R2.15
 
 fitz_ra wrote
  I know this is posted a lot, I've been through about 40 messages reading
  how to do this so let me apologize in advance because I can't get this
  operation to work unlike the many examples shown.
 
  I have a 2 row matrix
  temp
 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
  [,9][,10]
  [1,] 17.000 9.00 26.0  5.0 23.0 21.0 19.0 17.0
  10.0  63.
  [2,] 15.554 7.793718 33.29079 15.53094 20.44825 14.34443 11.83552 11.62997
  10.16019 115.2602
 
  I want to order the matrix using the second row in ascending order.  From
  the many examples (usually applied to columns) the typical solution
  appears to be:
  temp[order(temp[2,]),]
  Error: subscript out of bounds
 
  However as you can see I get an error here.
 
  When I run this one line command:
  sort(temp[2,])
   [1]   7.793718  10.160190  11.629973  11.835520  14.344426  15.530939
  15.553999  20.448249  33.290789
  [10] 115.260192
 
  This works but I want the matrix to update and the corresponding values of
  row 1 to switch with the sort.
 
 Maybe consider the order function 
 
 orig - matrix(c(10,20,30,3,1,2), nrow=2, byrow=TRUE)
 
 new -t(apply(orig,1,function(x) x[order(orig[2,])]))
 
  orig
  [,1] [,2] [,3]
 [1,]   10   20   30
 [2,]312
  new
  [,1] [,2] [,3]
 [1,]   20   30   10
 [2,]123
 
 HTH
 
 Pete
 
 
 
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Ordering-a-matrix-by-row-
 value-in-R2-15-tp4662337p4662340.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@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.

__
R-help@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.


Re: [R] Ordering Table Columns

2013-03-02 Thread Pete Brecknock
cdouglass wrote
 Hello all,
 
 Totally new to this and I'm just doing a frequency distribution analysis
 on T-shirt sales by size.  I have a .csv with 60 orders.  I read in the
 data using read.csv.  If I look at the summary() or table() of the data it
 looks fine, except that the shirt sizes are alphabetical rather than from
 S-XXL--so the bar graph loses the shape of the data based on size.
 
 All I want to do is get the table to arrange the data:
 S M L XL XXL
 
 Here's the code that I've run that got me closer to what I want.  It seems
 like it should be simple, but going through the R in a Nutshell and
 asking Google as many different ways as I can think to phrase it are
 turning up nothing.
 
 shirt - read.csv(http://localhost/examples/tshirt_purchases.csv;,
 header=TRUE, sep = ,, nrows=60)
 shirt.table-summary(shirt)
 shirt.table
  Shirt.Size
  L  :20
  M  :20
  S  :11
  XL : 7
  XXL: 2  
 
 What I want is:
 
 Shirt.Size
 S  :11   
 M  :20 
 L  :20  
  XL : 7
  XXL: 2  
 
 Does anyone know how to do this, or am I coming at it from the wrong
 direction?
 If this has been answered previously and I've just failed to find it in my
 searches, please accept my apologies.  
 
 Many Thanks,
 Chris

Think you want to have a look at factors 

Typing ?factor will throw up the relevant help pages  

# Your Data
tbl - read.table(header = TRUE, text = 
 ShirtSize Number 
 L 20 
 M 20 
 S 11 
 XL 7 
 XXL 2   
)

# ShirtSize Alphabetical
tbl[tbl$ShirtSize,]

# Reorder Factor
tbl$ShirtSize = factor(tbl$ShirtSize, levels=c(S,M,L,XL,XXL))

# ShirtSize Order by Size
tbl[tbl$ShirtSize,]


Pete



--
View this message in context: 
http://r.789695.n4.nabble.com/Ordering-Table-Columns-tp4660110p4660129.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


[R] Ordering List Items Chronologically

2012-11-20 Thread Simon Kiss
Dear colleagues,
Is there a way to order list items by date? I have a series of surveys in a 
list where the name of each list item is the date the survey was taken but the 
list items are out of order.  Each data frame has a variable in it with the 
survey date as well, if that helps.
Yours, Simon Kiss
#Sample Data
mylist-list('1991-01-01'=data.frame(a=rep(5,5), 
survey.date=rep(as.Date('1991-01-01', format='%Y-%m-%d'))), 
'1979-01-01'=data.frame(aa=rep(5,5), survey.date=rep(as.Date('1979-01-01', 
format='%Y-%m-%d'), 5)), '2001-01-01'=data.frame(c=rep(6,5), 
survey.date=rep(as.Date('2001-01-01', format='%Y-%m-%d'), 5)))
mylist

__
R-help@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.


Re: [R] Ordering List Items Chronologically

2012-11-20 Thread William Dunlap
o - order(as.Date(names(mylist)))
myListInDateOrder - mylist[o]

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf
 Of Simon Kiss
 Sent: Tuesday, November 20, 2012 8:41 AM
 To: r-help@r-project.org
 Subject: [R] Ordering List Items Chronologically
 
 Dear colleagues,
 Is there a way to order list items by date? I have a series of surveys in a 
 list where the
 name of each list item is the date the survey was taken but the list items 
 are out of order.
 Each data frame has a variable in it with the survey date as well, if that 
 helps.
 Yours, Simon Kiss
 #Sample Data
 mylist-list('1991-01-01'=data.frame(a=rep(5,5), 
 survey.date=rep(as.Date('1991-01-01',
 format='%Y-%m-%d'))), '1979-01-01'=data.frame(aa=rep(5,5),
 survey.date=rep(as.Date('1979-01-01', format='%Y-%m-%d'), 5)), '2001-01-
 01'=data.frame(c=rep(6,5), survey.date=rep(as.Date('2001-01-01', 
 format='%Y-%m-%d'),
 5)))
 mylist
 
 __
 R-help@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.

__
R-help@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.


Re: [R] Ordering List Items Chronologically

2012-11-20 Thread Sarah Goslee
As long as all your names of list elements are in the same format,
this should do it:

 mylist[order(names(mylist))]

Thanks for the reproducible example,
Sarah

On Tue, Nov 20, 2012 at 11:40 AM, Simon Kiss sjk...@gmail.com wrote:
 Dear colleagues,
 Is there a way to order list items by date? I have a series of surveys in a 
 list where the name of each list item is the date the survey was taken but 
 the list items are out of order.  Each data frame has a variable in it with 
 the survey date as well, if that helps.
 Yours, Simon Kiss
 #Sample Data
 mylist-list('1991-01-01'=data.frame(a=rep(5,5), 
 survey.date=rep(as.Date('1991-01-01', format='%Y-%m-%d'))), 
 '1979-01-01'=data.frame(aa=rep(5,5), survey.date=rep(as.Date('1979-01-01', 
 format='%Y-%m-%d'), 5)), '2001-01-01'=data.frame(c=rep(6,5), 
 survey.date=rep(as.Date('2001-01-01', format='%Y-%m-%d'), 5)))
 mylist


--
Sarah Goslee
http://www.functionaldiversity.org

__
R-help@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.


[R] ordering of factor levels in regression changes result

2012-02-03 Thread Tulinsky, Thomas
I was surprised to find that just changing the base level of a factor variable 
changed the number of significant coefficients in the solution.

I was surprised at this and want to know how I should choose the order of the 
factors, if the order affects the result.

Here is the small example. It is taken from 'The R Book', Crawley  p. 365. 

The data is at 
http://www.bio.ic.ac.uk/research/mjcraw/therbook/data/competition.txt

In R

comp-read.table(C:\\Temp\\competition.txt, header=T)

attach(comp)

Data has dependent variable 'biomass' and different types of 'clipping' that 
were done:
Control (none), n25, n50, r10, r5:

 summary(comp)
   biomass clipping
   Min.   :415.0   control:6  
1st Qu.:508.8   n25:6  
Median :568.0   n50:6  
Mean   :561.8   r10:6  
3rd Qu.:631.8   r5 :6  
Max.   :731.0  

List mean Biomass of each type of Clipping:

aggregate (comp$biomass, list (comp$clipping) , mean)
 Group.1x
control 465.1667
n25 553.
n50 569.
r10 610.6667
 r5 610.5000

do regression - get same result as book p. 365
Clipping type 'control' is not in list of coefficients because it is first 
alphabetically so it is folded into Intercept

model-lm(biomass ~ clipping)
summary(model)

   Call:
   lm(formula = biomass ~ clipping)

   Residuals:
Min   1Q   Median   3Q  Max 
   -103.333  -49.6673.417   43.375  177.667 

   Coefficients:
   Estimate Std. Error t value Pr(|t|)
   (Intercept)   465.17  28.75  16.177  9.4e-15 ***
   clippingn2588.17  40.66   2.168  0.03987 *  
   clippingn50   104.17  40.66   2.562  0.01683 *  
   clippingr10   145.50  40.66   3.578  0.00145 ** 
   clippingr5145.33  40.66   3.574  0.00147 ** 
   ---
   Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

   Residual standard error: 70.43 on 25 degrees of freedom
   Multiple R-squared: 0.4077, Adjusted R-squared: 0.3129 
   F-statistic: 4.302 on 4 and 25 DF,  p-value: 0.008752 


Relevel - make 'n25' the base level of Clipping:

comp$clipping - relevel (comp$clipping, ref=n25)

summary(comp)
   biomass clipping
Min.   :415.0   n25:6  
1st Qu.:508.8   control:6  
Median :568.0   n50:6  
Mean   :561.8   r10:6  
3rd Qu.:631.8   r5 :6  
Max.   :731.0  

Redo LM with releveled data

modelRelev-lm(biomass~clipping, data=comp)

Different results. (Some parts, Residuals and Std Errors,  are the same)
Especially note the Pr and Signifcance columns are different.

summary(modelRelev)

   Call:
   lm(formula = biomass ~ clipping, data = comp)

   Residuals:  
Min   1Q   Median   3Q  Max 
   -103.333  -49.6673.417   43.375  177.667 

   Coefficients:
   Estimate Std. Error t value Pr(|t|)
   (Intercept)   553.33  28.75  19.244   2e-16 ***
   clippingcontrol   -88.17  40.66  -2.168   0.0399 *  
   clippingn5016.00  40.66   0.393   0.6973
   clippingr1057.33  40.66   1.410   0.1709
   clippingr5 57.17  40.66   1.406   0.1721
   ---
   Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

   Residual standard error: 70.43 on 25 degrees of freedom
   Multiple R-squared: 0.4077, Adjusted R-squared: 0.3129 
   F-statistic: 4.302 on 4 and 25 DF,  p-value: 0.008752

__
R-help@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.


Re: [R] ordering of factor levels in regression changes result

2012-02-03 Thread David Winsemius


On Feb 3, 2012, at 4:16 PM, Tulinsky, Thomas wrote:

I was surprised to find that just changing the base level of a  
factor variable changed the number of significant coefficients in  
the solution.


I was surprised at this and want to know how I should choose the  
order of the factors, if the order affects the result.


In the first model you are getting R's default contrast between the  
control levels and each of the other levels, while in the second you  
are getting contrasts between N25 and the others. I would think that  
the most interest would be on the first set of results , but it could  
also be that you are not testing for what your really want. Is it  
scientifically interesting to consider the ordinal scale of effects?  
Perhaps you should be looking at a linear or quadratic fit?


Looking at the text you cite, it becomes clear that you need to read  
the rest of the chapter before submitting questions to R-help.





Here is the small example. It is taken from 'The R Book', Crawley   
p. 365.


The data is at
http://www.bio.ic.ac.uk/research/mjcraw/therbook/data/competition.txt

In R


comp-read.table(C:\\Temp\\competition.txt, header=T)



attach(comp)


Data has dependent variable 'biomass' and different types of  
'clipping' that were done:

Control (none), n25, n50, r10, r5:


summary(comp)

  biomass clipping
  Min.   :415.0   control:6
   1st Qu.:508.8   n25:6
   Median :568.0   n50:6
   Mean   :561.8   r10:6
   3rd Qu.:631.8   r5 :6
   Max.   :731.0

List mean Biomass of each type of Clipping:


aggregate (comp$biomass, list (comp$clipping) , mean)

Group.1x
   control 465.1667
   n25 553.
   n50 569.
   r10 610.6667
r5 610.5000

do regression - get same result as book p. 365
Clipping type 'control' is not in list of coefficients because it is  
first alphabetically so it is folded into Intercept


In this case there are no other covariates,  so it is not so much  
folded into the intercept as it really IS the Intercept.





model-lm(biomass ~ clipping)
summary(model)


  Call:
  lm(formula = biomass ~ clipping)

  Residuals:
   Min   1Q   Median   3Q  Max
  -103.333  -49.6673.417   43.375  177.667

  Coefficients:
  Estimate Std. Error t value Pr(|t|)
  (Intercept)   465.17  28.75  16.177  9.4e-15 ***
  clippingn2588.17  40.66   2.168  0.03987 *
  clippingn50   104.17  40.66   2.562  0.01683 *
  clippingr10   145.50  40.66   3.578  0.00145 **
  clippingr5145.33  40.66   3.574  0.00147 **
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

  Residual standard error: 70.43 on 25 degrees of freedom
  Multiple R-squared: 0.4077, Adjusted R-squared: 0.3129
  F-statistic: 4.302 on 4 and 25 DF,  p-value: 0.008752


Relevel - make 'n25' the base level of Clipping:


comp$clipping - relevel (comp$clipping, ref=n25)



summary(comp)

  biomass clipping
   Min.   :415.0   n25:6
   1st Qu.:508.8   control:6
   Median :568.0   n50:6
   Mean   :561.8   r10:6
   3rd Qu.:631.8   r5 :6
   Max.   :731.0

Redo LM with releveled data


modelRelev-lm(biomass~clipping, data=comp)


Different results. (Some parts, Residuals and Std Errors,  are the  
same)

Especially note the Pr and Signifcance columns are different.


summary(modelRelev)


  Call:
  lm(formula = biomass ~ clipping, data = comp)

  Residuals:
   Min   1Q   Median   3Q  Max
  -103.333  -49.6673.417   43.375  177.667

  Coefficients:
  Estimate Std. Error t value Pr(|t|)
  (Intercept)   553.33  28.75  19.244   2e-16 ***
  clippingcontrol   -88.17  40.66  -2.168   0.0399 *
  clippingn5016.00  40.66   0.393   0.6973
  clippingr1057.33  40.66   1.410   0.1709
  clippingr5 57.17  40.66   1.406   0.1721
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

  Residual standard error: 70.43 on 25 degrees of freedom
  Multiple R-squared: 0.4077, Adjusted R-squared: 0.3129
  F-statistic: 4.302 on 4 and 25 DF,  p-value: 0.008752

__
R-help@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.


David Winsemius, MD
West Hartford, CT

__
R-help@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.


Re: [R] Ordering of stack in ggplot (package ggplot2)

2011-10-19 Thread swonder03
That worked great thank you. 

--
View this message in context: 
http://r.789695.n4.nabble.com/Ordering-of-stack-in-ggplot-package-ggplot2-tp3917159p3917520.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


[R] Ordering of stack in ggplot (package ggplot2)

2011-10-18 Thread swonder03
I'm trying to reproduce the 3rd graph on the page of this site:
http://learnr.wordpress.com/2009/03/17/ggplot2-barplots/ . However, the data
below produces a ggplot with the stacks sorted in alphabetical order from
the bottom up. I'd like the stacks to be in the order Europe, Asia,
Americas, Africa, Oceania. Is there an easy way to manipulate ggplot or
geom_bar to do this? 

/library(ggplot2)
df - structure(c(106487, 495681, 1597442,
2452577, 2065141, 2271925, 4735484, 3555352,
8056040, 4321887, 2463194, 347566, 621147,
1325727, 1123492, 800368, 761550, 1359737,
1073726, 36, 53, 141, 41538, 64759, 124160,
69942, 74862, 323543, 247236, 112059, 16595,
37028, 153249, 427642, 1588178, 2738157,
2795672, 2265696, 11951, 33424, 62469,
74720, 166607, 404044, 426967, 38972, 361888,
1143671, 1516716, 160037, 354804, 996944,
1716374, 1982735, 3615225, 4486806, 3037122,
17, 54, 55, 210, 312, 358, 857, 350, 7368,
8443, 6286, 1750, 7367, 14092, 28954, 80779,
176893, 354939, 446792, 3, 69911, 53144,
29169, 18005, 11704, 13363, 18028, 46547,
14574, 8954, 2483, 14693, 25467, 25215,
41254, 46237, 98263, 185986), .Dim = c(19,
5), .Dimnames = list(c(1820-30, 1831-40,
1841-50, 1851-60, 
1861-70, 1871-80,
1881-90, 1891-00, 
1901-10, 1911-20,
1921-30, 1931-40, 
1941-50, 1951-60,
1961-70, 1971-80, 
1981-90, 1991-00,
2001-06), c(Europe, Asia, 
Americas,
Africa, Oceania)))

df.m2 - melt(df)
df.m2 - rename(df.m2, c(X1 = Period, X2 = Region))

a - ggplot(df.m2, aes(x = Period, y = value/1e+06,
fill = Region)) + opts(title = 
Migration to the United States by
Source Region (1820-2006)) +
labs(x = NULL, y = Number of People (in millions)n,
fill = )
b - a + geom_bar(stat = identity, position = stack)
b - b + scale_fill_brewer(palette = Set1)

immigration_theme - theme_update(axis.text.x = theme_text(angle = 90,
hjust = 1), panel.grid.major = 
theme_line(colour = grey90),
panel.grid.minor = theme_blank(), panel.background = 
theme_blank(),
axis.ticks = theme_blank(), legend.position = right)

b/

Thanks in advance

--
View this message in context: 
http://r.789695.n4.nabble.com/Ordering-of-stack-in-ggplot-package-ggplot2-tp3917159p3917159.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Ordering of stack in ggplot (package ggplot2)

2011-10-18 Thread Dennis Murphy
Hi:

levels(df.m2$Region)
[1] Africa   Americas Asia Europe   Oceania

Reorder your Region factor to the following:

df.m2$Region - factor(df.m2$Region, levels = c('Europe', 'Asia',
'Americas', 'Africa', 'Oceania'))

Then recopy the code from the definition of a onward and you should
get what you want. Worked for me.

Dennis


On Tue, Oct 18, 2011 at 4:59 PM, swonder03 ramey.ste...@gmail.com wrote:
 I'm trying to reproduce the 3rd graph on the page of this site:
 http://learnr.wordpress.com/2009/03/17/ggplot2-barplots/ . However, the data
 below produces a ggplot with the stacks sorted in alphabetical order from
 the bottom up. I'd like the stacks to be in the order Europe, Asia,
 Americas, Africa, Oceania. Is there an easy way to manipulate ggplot or
 geom_bar to do this?

 /library(ggplot2)
 df - structure(c(106487, 495681, 1597442,
                                2452577, 2065141, 2271925, 4735484, 3555352,
                                8056040, 4321887, 2463194, 347566, 621147,
                                1325727, 1123492, 800368, 761550, 1359737,
                                1073726, 36, 53, 141, 41538, 64759, 124160,
                                69942, 74862, 323543, 247236, 112059, 16595,
                                37028, 153249, 427642, 1588178, 2738157,
                                2795672, 2265696, 11951, 33424, 62469,
                                74720, 166607, 404044, 426967, 38972, 361888,
                                1143671, 1516716, 160037, 354804, 996944,
                                1716374, 1982735, 3615225, 4486806, 3037122,
                                17, 54, 55, 210, 312, 358, 857, 350, 7368,
                                8443, 6286, 1750, 7367, 14092, 28954, 80779,
                                176893, 354939, 446792, 3, 69911, 53144,
                                29169, 18005, 11704, 13363, 18028, 46547,
                                14574, 8954, 2483, 14693, 25467, 25215,
                                41254, 46237, 98263, 185986), .Dim = c(19,
                                5), .Dimnames = list(c(1820-30, 1831-40,
                                                1841-50, 1851-60, 
 1861-70, 1871-80,
                                                1881-90, 1891-00, 
 1901-10, 1911-20,
                                                1921-30, 1931-40, 
 1941-50, 1951-60,
                                                1961-70, 1971-80, 
 1981-90, 1991-00,
                                                2001-06), c(Europe, 
 Asia, Americas,
                                                Africa, Oceania)))

 df.m2 - melt(df)
 df.m2 - rename(df.m2, c(X1 = Period, X2 = Region))

 a - ggplot(df.m2, aes(x = Period, y = value/1e+06,
                                                fill = Region)) + opts(title = 
 Migration to the United States by
 Source Region (1820-2006)) +
                labs(x = NULL, y = Number of People (in millions)n,
                                fill = )
 b - a + geom_bar(stat = identity, position = stack)
 b - b + scale_fill_brewer(palette = Set1)

 immigration_theme - theme_update(axis.text.x = theme_text(angle = 90,
                                hjust = 1), panel.grid.major = 
 theme_line(colour = grey90),
                panel.grid.minor = theme_blank(), panel.background = 
 theme_blank(),
                axis.ticks = theme_blank(), legend.position = right)

 b/

 Thanks in advance

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Ordering-of-stack-in-ggplot-package-ggplot2-tp3917159p3917159.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@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.


__
R-help@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.


Re: [R] Ordering of stack in ggplot (package ggplot2)

2011-10-18 Thread David Winsemius


On Oct 18, 2011, at 7:59 PM, swonder03 wrote:


I'm trying to reproduce the 3rd graph on the page of this site:
http://learnr.wordpress.com/2009/03/17/ggplot2-barplots/ . However,  
the data
below produces a ggplot with the stacks sorted in alphabetical order  
from
the bottom up. I'd like the stacks to be in the order Europe,  
Asia,
Americas, Africa, Oceania. Is there an easy way to manipulate  
ggplot or

geom_bar to do this?


Change the order of the levels in a factor variable:

 levels(df.m2$Var2)
[1] Africa   Americas Asia Europe   Oceania
 levels(df.m2$Var2) - c(Europe, Asia, Americas , Africa  ,   
Oceania )



My efforts to replicate your code founded on the fact that your  
rename() operation seemed to have the wrong targets (or perhaps it is  
from a package you did not tell us about. (I did load rehape2.


--
david.



/library(ggplot2)
df - structure(c(106487, 495681, 1597442,
2452577, 2065141, 2271925, 4735484, 3555352,
8056040, 4321887, 2463194, 347566, 621147,
1325727, 1123492, 800368, 761550, 1359737,
1073726, 36, 53, 141, 41538, 64759, 124160,
69942, 74862, 323543, 247236, 112059, 16595,
37028, 153249, 427642, 1588178, 2738157,
2795672, 2265696, 11951, 33424, 62469,
74720, 166607, 404044, 426967, 38972, 361888,
1143671, 1516716, 160037, 354804, 996944,
1716374, 1982735, 3615225, 4486806, 3037122,
17, 54, 55, 210, 312, 358, 857, 350, 7368,
8443, 6286, 1750, 7367, 14092, 28954, 80779,
176893, 354939, 446792, 3, 69911, 53144,
29169, 18005, 11704, 13363, 18028, 46547,
14574, 8954, 2483, 14693, 25467, 25215,
41254, 46237, 98263, 185986), .Dim = c(19,
5), .Dimnames = list(c(1820-30, 1831-40,
1841-50, 1851-60, 1861-70, 
1871-80,
1881-90, 1891-00, 1901-10, 
1911-20,
1921-30, 1931-40, 1941-50, 
1951-60,
1961-70, 1971-80, 1981-90, 
1991-00,
2001-06), c(Europe, Asia, 
Americas,
Africa, Oceania)))

df.m2 - melt(df)
df.m2 - rename(df.m2, c(X1 = Period, X2 = Region))

a - ggplot(df.m2, aes(x = Period, y = value/1e+06,
		fill = Region)) + opts(title = Migration to the United States  
by

Source Region (1820-2006)) +
labs(x = NULL, y = Number of People (in millions)n,
fill = )
b - a + geom_bar(stat = identity, position = stack)
b - b + scale_fill_brewer(palette = Set1)

immigration_theme - theme_update(axis.text.x = theme_text(angle = 90,
hjust = 1), panel.grid.major = theme_line(colour = 
grey90),
panel.grid.minor = theme_blank(), panel.background = 
theme_blank(),
axis.ticks = theme_blank(), legend.position = right)

b/

Thanks in advance

--
View this message in context: 
http://r.789695.n4.nabble.com/Ordering-of-stack-in-ggplot-package-ggplot2-tp3917159p3917159.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


David Winsemius, MD
West Hartford, CT

__
R-help@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.


[R] ordering rows within CrossTable

2011-09-10 Thread Luca Meyer
Hi,

I am running the following -masked- code:

set.seed(23)
city - sample(c(C1,C2),size=100,replace=T)
reason - sample(c(R1,R2,R3,R4),size=100,replace=T)
df - data.frame(city,reason)
library(gmodels)
CrossTable(df$reason,df$city,prop.r=F,prop.c=F,prop.t=F,prop.chisq=F)

And I get the following output:

 | df$city 
   df$reason |C1 |C2 | Row Total | 
-|---|---|---|
  R1 | 4 |13 |17 | 
-|---|---|---|
  R2 |19 |10 |29 | 
-|---|---|---|
  R3 |12 |13 |25 | 
-|---|---|---|
  R4 |11 |18 |29 | 
-|---|---|---|
Column Total |46 |54 |   100 | 
-|---|---|---|

I would like to have the df$reason sorted by decreasing count on the Row Total 
- that is showing R2, R4, R3 and finally R1 - how can I do that?

Thanks,

Luca


Mr. Luca Meyer
www.lucameyer.com
R version 2.13.1 (2011-07-08)
Mac OS X 10.6.8







[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] ordering rows within CrossTable

2011-09-10 Thread Marc Schwartz
On Sep 10, 2011, at 4:03 PM, Luca Meyer wrote:

 Hi,
 
 I am running the following -masked- code:
 
 set.seed(23)
 city - sample(c(C1,C2),size=100,replace=T)
 reason - sample(c(R1,R2,R3,R4),size=100,replace=T)
 df - data.frame(city,reason)
 library(gmodels)
 CrossTable(df$reason,df$city,prop.r=F,prop.c=F,prop.t=F,prop.chisq=F)
 
 And I get the following output:
 
 | df$city 
   df$reason |C1 |C2 | Row Total | 
 -|---|---|---|
  R1 | 4 |13 |17 | 
 -|---|---|---|
  R2 |19 |10 |29 | 
 -|---|---|---|
  R3 |12 |13 |25 | 
 -|---|---|---|
  R4 |11 |18 |29 | 
 -|---|---|---|
 Column Total |46 |54 |   100 | 
 -|---|---|---|
 
 I would like to have the df$reason sorted by decreasing count on the Row 
 Total - that is showing R2, R4, R3 and finally R1 - how can I do that?
 
 Thanks,
 
 Luca


Hi,

Two things:

To respond to your specific query, you need to reorder the levels of df$reason, 
based upon the frequency of each level. CrossTable() is built upon table() and 
the default ordering of the rows and columns in the table will be in the order 
of the factor levels:

Use table() to get the counts:

 table(df$reason)

R2 R4 R3 R1 
29 29 25 17 

Now sort the table in decreasing order:

 sort(table(df$reason), decreasing = TRUE)

R2 R4 R3 R1 
29 29 25 17 

Now get the names:

 names(sort(table(df$reason), decreasing = TRUE))
[1] R2 R4 R3 R1


Finally, set the levels of df$reason using the above values:

df$reason - factor(df$reason, 
levels = names(sort(table(df$reason), 
decreasing = TRUE)))


 CrossTable(df$reason,df$city,prop.r=F,prop.c=F,prop.t=F,prop.chisq=F)

 
   Cell Contents
|-|
|   N |
|-|

 
Total Observations in Table:  100 

 
 | df$city 
   df$reason |C1 |C2 | Row Total | 
-|---|---|---|
  R2 |19 |10 |29 | 
-|---|---|---|
  R4 |11 |18 |29 | 
-|---|---|---|
  R3 |12 |13 |25 | 
-|---|---|---|
  R1 | 4 |13 |17 | 
-|---|---|---|
Column Total |46 |54 |   100 | 
-|---|---|---|



The second point is that I am no longer maintaining the code for CrossTable(), 
albeit it has yet to be removed by the gmodels package maintainer. You should 
consider using the version of CrossTable() in the 'descr' package by Jakson 
Aquino on CRAN.


HTH,

Marc Schwartz

__
R-help@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.


Re: [R] Ordering a matrix based on cluster no

2011-06-27 Thread Aparna Sampath
Thanks for the help! But when I tried it, it does not work the same way I
want. :(
 after combining the two matrices, they look like this:


 V1V2   X   TEL.AML1.C41  
Hyperdip.50.C23
1 TEL.AML1.C41   1TEL.AML1.C41   1.000  0.
2  Hyperdip.50.C23   1Hyperdip.50.C230.000  1.
3   BCR.AB.LC11BCR.AB.LC1   0.1212121  0.78125000
4  Hyperdip.50.C13   1Hyperdip.50.C130.000  1.
6   TEL.AML1.91T.ALL.C5  0.000  0.03225807
7   TEL.AML1.81TEL.AML1.9  1.000  0.
8   Hyperdip.50.C71   TEL.AML1.8   1.000  0.
9 TEL.AML1.C37   1   Hyperdip.50.C7   0.000  1.
11TEL.AML1.C47  1   TEL.AML1.C371.000  0.
13  Hyperdip.50.11   1   MLL.60.000  0.03225807


when i do :  orddata1  - df2_a[order(df2_a[,1],decreasing=T),] 

I get the result:

   V1   V2   X   TEL.AML1.C41
Hyperdip.50.C23
22   TEL.AML1.C49   1   TEL.AML1.2M.11  0.
11   TEL.AML1.C47   1   TEL.AML1.C37  1 0.
1TEL.AML1.C41   1TEL.AML1.C41 1  0.
9TEL.AML1.C37   1Hyperdip.50.C70  1.
6TEL.AML1.9  1T.ALL.C5 0
0.03225807
7TEL.AML1.8  1TEL.AML1.9 1
0.
16  TEL.AML1.2M.4  1Hyperdip.50.110 1.
19  TEL.AML1.2M.1  1TEL.AML1.2M.41 0.
15  Hyperdip.50.R2  1T.ALL.C10   0
0.
20  Hyperdip.50.C9  1BCR.ABL.Hyperdip.R5 0 1.


The results are not right! I want it to look for the gene TEL.AML1.C49 in
the second matrix and group it accordingly. 

Aparna 

--
View this message in context: 
http://r.789695.n4.nabble.com/Ordering-a-matrix-based-on-cluster-no-tp3625956p3627017.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Ordering a matrix based on cluster no

2011-06-27 Thread John Kane
Hi
First a handy point : When supplying sample data it is a good idea to use 
dput(). See ?dput for an explanation.  It makes it much easier to see what the 
data looks like and to work with it.  Sample data pasted into a e-mail can get 
badly mangled.  Yours was not bad but still need a bit of cleaning up.  I think 
I'll suggest that this idea goes in the posting guidelines.

Next point: Do you really have two matrices? It looks from the examples you 
have supplied that you have two data.frames unless all the numerics in the two 
data sets actually are character values.  Try str(data.set) to see what they 
are.

On to more substantive matters.  It looks like I misread part of the post. I 
had assumed that both the 100 X 100 matrix and the 2 X 100 were sorted already 
and just needed to be joined and sorted.

It looks to me like what you want to do is to merge (?merge for info)  the two 
data sets based on the gene names (in merge they should have the same variable 
name to make life easy ) and then apply the order command to sort by cluster

Of the top of my head, and using the example names I used earlier  I thin;k you 
want something like  this assuming a common name for the gene name.

merge (smat, bmat,  by= “gene”)  # untested

Then apply the order command.

I hope I understood the problem this time

--- On Mon, 6/27/11, Aparna Sampath aparna.sampat...@gmail.com wrote:

 From: Aparna Sampath aparna.sampat...@gmail.com
 Subject: Re: [R] Ordering a matrix based on cluster no
 To: r-help@r-project.org
 Received: Monday, June 27, 2011, 2:03 AM
 Thanks for the help! But when I tried
 it, it does not work the same way I
 want. :(
  after combining the two matrices, they look like this:
 
 
          
    V1         
   V2           
    X       
    TEL.AML1.C41  
 Hyperdip.50.C23
 1 
    TEL.AML1.C41   1 
   TEL.AML1.C41   
    1.000      0.
 2  Hyperdip.50.C23   1   
 Hyperdip.50.C23    0.000     
 1.
 3       BCR.AB.LC1   
 1    BCR.AB.LC1       
    0.1212121      0.78125000
 4  Hyperdip.50.C13   1   
 Hyperdip.50.C13    0.000     
 1.
 6       TEL.AML1.9   
 1    T.ALL.C5         
     0.000      0.03225807
 7       TEL.AML1.8   
 1    TEL.AML1.9         
 1.000      0.
 8   Hyperdip.50.C7   
 1   TEL.AML1.8       
    1.000      0.
 9 
    TEL.AML1.C37   1   Hyperdip.50.C7 
      0.000     
 1.
 11    TEL.AML1.C47 
 1   TEL.AML1.C37       
 1.000      0.
 13 
 Hyperdip.50.11   1   MLL.6 
                
   0.000      0.03225807
 
 
 when i do :  orddata1  -
 df2_a[order(df2_a[,1],decreasing=T),] 
 
 I get the result:
 
            V1 
          V2   
            
    X       
    TEL.AML1.C41
 Hyperdip.50.C23
 22   TEL.AML1.C49   1 
      TEL.AML1.2M.1     
       1         
 0.
 11   TEL.AML1.C47   1 
      TEL.AML1.C37     
         1     
    0.
 1    TEL.AML1.C41   1   
     TEL.AML1.C41         
    1         
 0.
 9    TEL.AML1.C37   1   
     Hyperdip.50.C7       
     0         
 1.
 6    TEL.AML1.9      1 
       T.ALL.C5       
              0 
       
 0.03225807
 7    TEL.AML1.8      1 
       TEL.AML1.9       
          1     
   
 0.
 16  TEL.AML1.2M.4  1       
 Hyperdip.50.11           
 0         1.
 19  TEL.AML1.2M.1  1       
 TEL.AML1.2M.4           
 1         0.
 15  Hyperdip.50.R2  1       
 T.ALL.C10             
      0        
 0.
 20  Hyperdip.50.C9  1       
 BCR.ABL.Hyperdip.R5     0   
      1.
 
 
 The results are not right! I want it to look for the gene
 TEL.AML1.C49 in
 the second matrix and group it accordingly. 
 
 Aparna 
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Ordering-a-matrix-based-on-cluster-no-tp3625956p3627017.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@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.


__
R-help@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.


[R] Ordering a matrix based on cluster no

2011-06-26 Thread Aparna Sampath
Hi All

I have a symmetric matrix of genes ( 100x100 matrix). I also have a matrix
(100x2) of two columns where column 1 has the gene names and column 2 has
the cluster it belongs to (they are sorted and grouped based on the cluster
no).

I would like to order the rows and columns of the 100x 100 matrix such that
the first n genes correspond to cluster 1 and next n genes correspond to
cluster 2 and so on. The order of genes is taken from the sorted
matrix(100x2).

Can someone tell me how to do this in R.

I tried the grep() but I get a message saying that the length of pattern 1
so only first element will be compared. But i want to check for each gene in
the 100x100 matrix for its cluster number and then group it.

I also tried the order() but it did not help either.

Thanks for the help! :)

Aparna

-- 
Aparna Sampath
Master of Science (Bioinformatics)
Nanyang Technological University
Mob no : +65 91601854

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Ordering a matrix based on cluster no

2011-06-26 Thread John Kane
Combine the two matrices into one data.frame and order them
Example done using data.frames rather than matrices but just use use 
data.frame(x,y) to convert to a data.frame

bmat - data.frame(matrix(1:25,5))
smat - data.frame(aa= LETTERS[1:25],
   bb = rep(c(a,b,c, d, e),5))
df1  - data.frame(smat, bmat)
orddata  - df1[order(df1[,2],decreasing=TRUE),]

I hope this helps.


--- On Sun, 6/26/11, Aparna Sampath aparna.sampat...@gmail.com wrote:

 From: Aparna Sampath aparna.sampat...@gmail.com
 Subject: [R] Ordering a matrix based on cluster no
 To: r-help@r-project.org
 Received: Sunday, June 26, 2011, 9:42 AM
 Hi All
 
 I have a symmetric matrix of genes ( 100x100 matrix). I
 also have a matrix
 (100x2) of two columns where column 1 has the gene names
 and column 2 has
 the cluster it belongs to (they are sorted and grouped
 based on the cluster
 no).
 
 I would like to order the rows and columns of the 100x 100
 matrix such that
 the first n genes correspond to cluster 1 and next n genes
 correspond to
 cluster 2 and so on. The order of genes is taken from the
 sorted
 matrix(100x2).
 
 Can someone tell me how to do this in R.
 
 I tried the grep() but I get a message saying that the
 length of pattern 1
 so only first element will be compared. But i want to check
 for each gene in
 the 100x100 matrix for its cluster number and then group
 it.
 
 I also tried the order() but it did not help either.
 
 Thanks for the help! :)
 
 Aparna
 
 -- 
 Aparna Sampath
 Master of Science (Bioinformatics)
 Nanyang Technological University
 Mob no : +65 91601854
 
     [[alternative HTML version deleted]]
 
 __
 R-help@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.


__
R-help@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.


[R] Ordering every row of a matrix while ignoring off diagonal elements

2011-04-03 Thread Vivian Shih
Sorry if this is a stupid question but I've been stuck on how to code  
so that I can order rows of a matrix without paying attention to the  
diagonal elements.


Say, for example, I have a matrix d:

d

 [,1] [,2]  [,3]  [,4]
[1,] 0.00 2.384158 2.0065682 2.2998856
[2,] 2.384158 0.00 1.4599928 2.4333213
[3,] 2.006568 1.459993 0.000 0.9733285
[4,] 2.299886 0.00 0.9733285 0.000

Then I'd like ordered d to be like:
 [,1] [,2] [,3]
[1,]342
[2,]314
[3,]421
[4,]231

So subject 1's smallest value is in column 3. Subject 2's second  
smallest value would be 3, etc. Note that subject 4 has two zeros (a  
tie) but if the diagonals are not in the equation, then the minimum  
value for this subject is from column 2.


Right now I coded off diagonals as missing and then order it that way  
but I feel like it's cheating. Suggestions??


__
R-help@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.


Re: [R] Ordering every row of a matrix while ignoring off diagonal elements

2011-04-03 Thread jim holtman
I assume that this is what you did, and I would not call that
cheating; it is just a reasonable way to solve the problem:

 x - as.matrix(read.table(textConnection( 0.00 2.384158 2.0065682 
 2.2998856
+ 2.384158 0.00 1.4599928 2.4333213
+ 2.006568 1.459993 0.000 0.9733285
+ 2.299886 0.00 0.9733285 0.000)))
 closeAllConnections()
 # put NAs in diagonals
 diag(x) - NA
 # get the order
 x.ord - t(apply(x, 1, order))
 # remove last column since this is where NAs sort
 x.ord[, -ncol(x.ord)]
 [,1] [,2] [,3]
[1,]342
[2,]314
[3,]421
[4,]231



On Sun, Apr 3, 2011 at 11:51 PM, Vivian Shih v...@ucla.edu wrote:
 Sorry if this is a stupid question but I've been stuck on how to code so
 that I can order rows of a matrix without paying attention to the diagonal
 elements.

 Say, for example, I have a matrix d:

 d

         [,1]     [,2]      [,3]      [,4]
 [1,] 0.00 2.384158 2.0065682 2.2998856
 [2,] 2.384158 0.00 1.4599928 2.4333213
 [3,] 2.006568 1.459993 0.000 0.9733285
 [4,] 2.299886 0.00 0.9733285 0.000

 Then I'd like ordered d to be like:
     [,1] [,2] [,3]
 [1,]    3    4    2
 [2,]    3    1    4
 [3,]    4    2    1
 [4,]    2    3    1

 So subject 1's smallest value is in column 3. Subject 2's second smallest
 value would be 3, etc. Note that subject 4 has two zeros (a tie) but if
 the diagonals are not in the equation, then the minimum value for this
 subject is from column 2.

 Right now I coded off diagonals as missing and then order it that way but I
 feel like it's cheating. Suggestions??

 __
 R-help@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.




-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?

__
R-help@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.


[R] Ordering data.frame based on class

2011-03-28 Thread Vincy Pyne
Dear R helpers

Suppose I have a data.frame as given below -

my_dat = data.frame(class = c(XYZ, XYZ, XYZ, XYZ, XYZ,ABC, ABC, 
ABC, ABC, ABC ),  var1 = c(20, 14, 89, 81, 17, 44, 36, 41, 11, 36), var2 
= c(1001, 250, 456, 740, 380, 641, 111, 209, 830, 920))

 my_dat
   class var1 var2
1    XYZ   20 1001
2    XYZ   14  250
3    XYZ   89  456
4    XYZ   81  740
5    XYZ   17  380
6    ABC   44  641
7    ABC   36  111
8    ABC   41  209
9    ABC   11 
 830
10   ABC  20  920 

I wish to sort above data.frame class-wise on var1. Thus, Ineed to get


class    var1    var2

 
 
  XYZ  
  14
  250
 
 
  XYZ  
  17
  380
 
 
  XYZ  
  20
  1001
 
 
  XYZ  
  81
  740
 
 
  XYZ  
  89
  456
 
 
  ABC  
  11
  830
 
 
  ABC  
  20
  920
 
 
  ABC  
  36
  111
 
 
  ABC  
  41
  209
 
 
  ABC  
  44
  641
 

Kindly guide

Vincy



[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Ordering data.frame based on class

2011-03-28 Thread Henrique Dallazuanna
Try this:

my_dat[order(my_dat$class, -my_dat$var1, decreasing = TRUE),]

On Mon, Mar 28, 2011 at 5:55 PM, Vincy Pyne vincy_p...@yahoo.ca wrote:
 Dear R helpers

 Suppose I have a data.frame as given below -

 my_dat = data.frame(class = c(XYZ, XYZ, XYZ, XYZ, XYZ,ABC, ABC, 
 ABC, ABC, ABC ),  var1 = c(20, 14, 89, 81, 17, 44, 36, 41, 11, 36), 
 var2 = c(1001, 250, 456, 740, 380, 641, 111, 209, 830, 920))

 my_dat
    class var1 var2
 1    XYZ   20 1001
 2    XYZ   14  250
 3    XYZ   89  456
 4    XYZ   81  740
 5    XYZ   17  380
 6    ABC   44  641
 7    ABC   36  111
 8    ABC   41  209
 9    ABC   11
  830
 10   ABC  20  920

 I wish to sort above data.frame class-wise on var1. Thus, Ineed to get


 class    var1    var2



  XYZ
  14
  250


  XYZ
  17
  380


  XYZ
  20
  1001


  XYZ
  81
  740


  XYZ
  89
  456


  ABC
  11
  830


  ABC
  20
  920


  ABC
  36
  111


  ABC
  41
  209


  ABC
  44
  641


 Kindly guide

 Vincy



        [[alternative HTML version deleted]]


 __
 R-help@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.





-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

__
R-help@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.


Re: [R] Ordering data.frame based on class

2011-03-28 Thread Vincy Pyne
Dear sir,

Thanks for the great solution.

Regards

Vincy

--- On Mon, 3/28/11, Henrique Dallazuanna www...@gmail.com wrote:

From: Henrique Dallazuanna www...@gmail.com
Subject: Re: [R] Ordering data.frame based on class
To: Vincy Pyne vincy_p...@yahoo.ca
Cc: r-help@r-project.org
Received: Monday, March 28, 2011, 9:02 PM

Try this:

my_dat[order(my_dat$class, -my_dat$var1, decreasing = TRUE),]

On Mon, Mar 28, 2011 at 5:55 PM, Vincy Pyne vincy_p...@yahoo.ca wrote:
 Dear R helpers

 Suppose I have a data.frame as given below -

 my_dat = data.frame(class = c(XYZ, XYZ, XYZ, XYZ, XYZ,ABC, ABC, 
 ABC, ABC, ABC ),  var1 = c(20, 14, 89, 81, 17, 44, 36, 41, 11, 36), 
 var2 = c(1001, 250, 456, 740, 380, 641, 111, 209, 830, 920))

 my_dat
    class var1 var2
 1    XYZ   20 1001
 2    XYZ   14  250
 3    XYZ   89  456
 4    XYZ   81  740
 5    XYZ   17  380
 6    ABC   44  641
 7    ABC   36  111
 8    ABC   41  209
 9    ABC   11
  830
 10   ABC  20  920

 I wish to sort above data.frame class-wise on var1. Thus, Ineed to get


 class    var1    var2



  XYZ
  14
  250


  XYZ
  17
  380


  XYZ
  20
  1001


  XYZ
  81
  740


  XYZ
  89
  456


  ABC
  11
  830


  ABC
  20
  920


  ABC
  36
  111


  ABC
  41
  209


  ABC
  44
  641


 Kindly guide

 Vincy



        [[alternative HTML version deleted]]


 __
 R-help@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.





-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O



[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Ordering several histograms

2011-03-06 Thread Uwe Ligges



On 05.03.2011 18:40, djbirdnerd wrote:

not yet, but i have only just started programming in r...
I don't know if i will able to...



Without quoting the former thread and without replying to a particular 
person (rather than the mailing list only): Do you expect anybody on the 
mailing list knows what you are talking about?


Uwe Ligges



--
View this message in context: 
http://r.789695.n4.nabble.com/Ordering-several-histograms-tp382p3336869.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


__
R-help@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.


Re: [R] Ordering several histograms

2011-03-05 Thread djbirdnerd
not yet, but i have only just started programming in r...
I don't know if i will able to...

--
View this message in context: 
http://r.789695.n4.nabble.com/Ordering-several-histograms-tp382p3336869.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


[R] Ordering several histograms

2011-03-03 Thread djbirdnerd
Hallo everyone,

I want to evaluate the change of the distribution for several size classes.
How can i order these separate histograms with the same y-axis along a
common x-axis according to their size classes. It would like it to look a
bit like this
(http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=109) without
the quantile regression. I can produce the separate histograms, but have no
clue how to merge them. i can put them next to each with separate x- and
y-axes. 

Much obliged,

Kenneth



--
View this message in context: 
http://r.789695.n4.nabble.com/Ordering-several-histograms-tp382p382.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Ordering several histograms

2011-03-03 Thread Scott Chamberlain
You could get close with the ggplot2 package using the function facet_grid or 
facet_wrap, but each histogram would be on a separate x-axis

Scott
On Thursday, March 3, 2011 at 8:00 AM, djbirdnerd wrote: 
 Hallo everyone,
 
 I want to evaluate the change of the distribution for several size classes.
 How can i order these separate histograms with the same y-axis along a
 common x-axis according to their size classes. It would like it to look a
 bit like this
 (http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=109) without
 the quantile regression. I can produce the separate histograms, but have no
 clue how to merge them. i can put them next to each with separate x- and
 y-axes. 
 
 Much obliged,
 
 Kenneth
 
 
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Ordering-several-histograms-tp382p382.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@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.
 

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Ordering several histograms

2011-03-03 Thread csrabak

Em 3/3/2011 12:00, djbirdnerd escreveu:

Hallo everyone,

I want to evaluate the change of the distribution for several size classes.
How can i order these separate histograms with the same y-axis along a
common x-axis according to their size classes. It would like it to look a
bit like this
(http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=109) without
the quantile regression. I can produce the separate histograms, but have no
clue how to merge them. i can put them next to each with separate x- and
y-axes.

Much obliged,


Kenneth,

Have tried to adapt the R code which is published in the link you did post?

--
Cesar Rabak

__
R-help@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.


Re: [R] Ordering box plots

2011-01-24 Thread Stuart Luppescu
On Sun, 2011-01-23 at 17:37 -0600, Stuart Luppescu wrote:
[snip] Thanks to Ben and Dennis for their help, but right after I sent
the original message, I figured out how to solve my problem. I noticed
that boxplot() contains the at= argument. To get the box locations, I
used a line like this:

box.locs - order(order(aggregate(meas.tab[,meas.name], by=list(meas.tab$unit), 
mean, na.rm=T)$x))

-- 
Stuart Luppescu -=- slu .at. ccsr.uchicago.edu
University of Chicago -=- CCSR 
才文と智奈美の父 -=-Kernel 2.6.36-gentoo-r5
If you give people a linear model function you give
 them something dangerous.-- John Fox  
 useR! 2004, Vienna (May 2004)  
 
 
 
 
 
 
__
R-help@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.


[R] Ordering box plots

2011-01-23 Thread Stuart Luppescu
Hello all, I want box plots by group to display in order of increasing
mean (or median) of each group but can't seem to figure it out and
couldn't find anything on R-seek, either. 

My data looks like this:

   meas unit  sid gradersprti
1  2.24 1002 9902NA 0.860
2  3.04 1007 43589520 3 0.940
3  4.95 2002 39910470 5 1.530
4  2.24 2002 39986280 5 1.2755861
5  3.04 2002 40534857 5 1.0551474
6  4.95 2002 40650784 5 1.530
7  4.95 1001 40963456 5 1.530
8  2.24 2002 41730862 5 0.8642893
9  0.84 2002 41813806 5 1.2282878
10 3.04 2002 41822848 5 1.0551474

I'm plotting meas grouped by unit.

Here are my (unsuccessful) ideas:
1) save the plot data (call it bxp.info) to an object, reorder all the
data according to bxp.info$data[3,], and then plot it with bxp().
Couldn't figure out how to reorder all the elements of bxp.info (because
they are all different types and lengths?)
2) calculate the means by group, get ordered factors of the group means,
merge the ordered factors back into the original data frame, and plot
the values by the order of the means. Here is the code I used:

by.schl.order - 
as.data.frame(cbind(units,as.ordered(order(aggregate(meas.tab[,meas], 
by=list(meas.tab$unit), mean, na.rm=T)$x
   
names(by.schl.order) - c(unit, by.schl.plot.order)

meas.tab - merge(meas.tab, by.schl.order, by=unit)

boxplot(meas.tab[,meas] ~ meas.tab$by.schl.plot.order)

For some reason, the plot order (by.schl.plot.order) ends up as a
numeric instead of an ordered factor when put in the data frame,

class(meas.tab$by.schl.plot.order)
[1] numeric

and the boxes plot in the original order. I even tried this:

 boxplot(meas.tab[,meas] ~ as.ordered(meas.tab$by.schl.plot.order)

but that didn't do any better. I would think people would want to do
this all the time. There must be an easy way to do it but I can't figure
it out. Can anyone help me?
-- 
Stuart Luppescu -=- slu .at. ccsr.uchicago.edu
University of Chicago -=- CCSR 
才文と智奈美の父 -=-Kernel 2.6.36-gentoo-r5
It seems that you are facing a very serious
 fortune(122) problem.-- Jean R. Lobry (in
 reply to a user that quickly needed help for his
 PhD   thesis, without properly checking the
 documentation)   R-help (May 2006)  
 
 
 
 
__
R-help@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.


Re: [R] Ordering box plots

2011-01-23 Thread Ben Bolker
Stuart Luppescu slu at ccsr.uchicago.edu writes:

 
 I want box plots by group to display in order of increasing
 mean (or median) of each group but can't seem to figure it out and
 couldn't find anything on R-seek, either. 
 

  ?reorder ... ?

__
R-help@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.


[R] ordering a vector

2011-01-21 Thread Francesco Petrogalli
Hi,
is there a R function that order a matrix according to some criteria
based on the rows(or cols) of that matrix?

For example, let's say that my matrix S is composed by n rows S_1,
S_2,.., S_n and that I compute some real value g_i=g(S_i) for each
row.
Then I want to order this set of g_i (from smaller to bigger) and
order the correspondent row to the new position.

Is it possible (apart from looping on the index) to do this with some
predefined R function?

Thanks,

Francesco

__
R-help@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.


Re: [R] ordering a vector

2011-01-21 Thread jim holtman
look at 'order'

yourMatrix[order(yourMatrix[, 'yourCol']), ]

On Fri, Jan 21, 2011 at 2:38 PM, Francesco Petrogalli
francesco.petroga...@gmail.com wrote:
 Hi,
 is there a R function that order a matrix according to some criteria
 based on the rows(or cols) of that matrix?

 For example, let's say that my matrix S is composed by n rows S_1,
 S_2,.., S_n and that I compute some real value g_i=g(S_i) for each
 row.
 Then I want to order this set of g_i (from smaller to bigger) and
 order the correspondent row to the new position.

 Is it possible (apart from looping on the index) to do this with some
 predefined R function?

 Thanks,

 Francesco

 __
 R-help@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.




-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?

__
R-help@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.


Re: [R] ordering a vector

2011-01-21 Thread Peter Langfelder
I think you want the following, assuming you defined your function g():

gValues = apply(S, 1, g);

Sordered = S[order(gValues), ]

Peter

On Fri, Jan 21, 2011 at 11:38 AM, Francesco Petrogalli
francesco.petroga...@gmail.com wrote:
 Hi,
 is there a R function that order a matrix according to some criteria
 based on the rows(or cols) of that matrix?

 For example, let's say that my matrix S is composed by n rows S_1,
 S_2,.., S_n and that I compute some real value g_i=g(S_i) for each
 row.
 Then I want to order this set of g_i (from smaller to bigger) and
 order the correspondent row to the new position.

 Is it possible (apart from looping on the index) to do this with some
 predefined R function?

 Thanks,

 Francesco

 __
 R-help@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.


__
R-help@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.


[R] Ordering Duplicates for Selection

2010-10-05 Thread C C

Hi all,

I've found a lot of helpful info regarding identifying and deleting duplicates 
but I'd like to do something a little different - I'd like to identify the 
duplicate values but instead of deletion, label them with a value.  

I am working with historical data regarding school courses:



Student Number  Course  Final Mark  
 Completed
Date

1  12345678 Soc101  34  
 02-04-2003

2  12345678 Soc101  62  
 31-11-2004

3  12345678 Psy104  63  
 03-05-2003

4  23456789 Soc101  73  
 02-04-2003

5  23456789 Psy104  76  
 25-02-2004


In this data frame, records 1 and 2 contain data for the same student taking 
the same course.  In record 1, the student failed (Final Mark), took the course 
again (Completed Date) and finally passed (Final Mark) in record 2.

I'd like to be able to work with the data so that I could summarize the 
achievement distribution for the first attempt records and then compare it to 
the achievement distribution for the second attempt records.  In Excel I'd use 
something like COUNTIF($A$2:A2,A2) in a new column and then summarize the 1 
values and 2 values.

  OrderStudent Number  Course  
Final Mark   Completed Date

1  1  12345678 Soc101   
   34   02-04-2003

2  2  12345678 Soc101   
   62   31-11-2004

3  1  12345678 Psy104   
   63   03-05-2003

4  1  23456789 Soc101   
   73   02-04-2003

5  1  23456789 Psy104   
   76   25-02-2004


I suspect the answer is in the list discussions on deleting duplicate records 
but I'm still familiarizing myself with R and I'm not at a point to be able to 
see how it could be modified.  Any thoughts?

Cheers,
Chris
  
[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Ordering Duplicates for Selection

2010-10-05 Thread jim holtman
Here is a way of putting Order on your data:

 x
  V1   V2 V3 V4 V5
1  1 12345678 Soc101 34 02-04-2003
2  2 12345678 Soc101 62 31-11-2004
3  3 12345678 Psy104 63 03-05-2003
4  4 23456789 Soc101 73 02-04-2003
5  5 23456789 Psy104 76 25-02-2004
 x$order - ave(x$V1, x$V2, x$V3, FUN=seq_along)
 x
  V1   V2 V3 V4 V5 order
1  1 12345678 Soc101 34 02-04-2003   1
2  2 12345678 Soc101 62 31-11-2004   2
3  3 12345678 Psy104 63 03-05-2003   1
4  4 23456789 Soc101 73 02-04-2003   1
5  5 23456789 Psy104 76 25-02-2004   1



On Tue, Oct 5, 2010 at 11:42 AM, C C ps...@hotmail.com wrote:

 Hi all,

 I've found a lot of helpful info regarding identifying and deleting 
 duplicates but I'd like to do something a little different - I'd like to 
 identify the duplicate values but instead of deletion, label them with a 
 value.

 I am working with historical data regarding school courses:



                Student Number              Course                  Final Mark 
           Completed
 Date

 1              12345678                             Soc101                  
 34                           02-04-2003

 2              12345678                             Soc101                  
 62                           31-11-2004

 3              12345678                             Psy104                  
 63                           03-05-2003

 4              23456789                             Soc101                  
 73                           02-04-2003

 5              23456789                             Psy104                  
 76                           25-02-2004


 In this data frame, records 1 and 2 contain data for the same student taking 
 the same course.  In record 1, the student failed (Final Mark), took the 
 course again (Completed Date) and finally passed (Final Mark) in record 2.

 I'd like to be able to work with the data so that I could summarize the 
 achievement distribution for the first attempt records and then compare it to 
 the achievement distribution for the second attempt records.  In Excel I'd 
 use something like COUNTIF($A$2:A2,A2) in a new column and then summarize the 
 1 values and 2 values.

              Order    Student Number              Course                  
 Final Mark           Completed Date

 1              1              12345678                             Soc101     
              34                           02-04-2003

 2              2              12345678                             Soc101     
              62                           31-11-2004

 3              1              12345678                             Psy104     
              63                           03-05-2003

 4              1              23456789                             Soc101     
              73                           02-04-2003

 5              1              23456789                             Psy104     
              76                           25-02-2004


 I suspect the answer is in the list discussions on deleting duplicate 
 records but I'm still familiarizing myself with R and I'm not at a point to 
 be able to see how it could be modified.  Any thoughts?

 Cheers,
 Chris

        [[alternative HTML version deleted]]

 __
 R-help@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.




-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

__
R-help@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.


Re: [R] Ordering data by variable

2010-09-03 Thread Joshua Wiley
On Thu, Sep 2, 2010 at 2:33 PM, Greg Snow greg.s...@imail.org wrote:
 Suggestion:  use the power of R.

 If x and y are independent then sorting y based on x is meaningless.

 If sorting y based on x is meaningful, then they are not independent.

 Trying to force non-independent things to pretend that they are independent 
 just causes future headaches.

 Part of the great power of R is the ability to group things together that 
 should be grouped.  The wise learn this and use it (in some cases (mine) that 
 wisdom comes at the expense of not having properly grouped in the past).

Yes, this is an excellent suggestion.  My workspace used to be like a
rock pile that my poor brain had to dig through, trying to remember
some truly awful combinations of capitalizations, '.' , '_' , and
numerals from my vain efforts to organize variables.  Dataframes (and
lists for those pesky variables with irregular lengths) were the rake
that brought peace and tranquility to the rock garden of my workspace.

Josh

 Learn the power of with/within, data= arguments, and apply style functions, 
 then you will be eager to combine things into data frames (or lists or ...) 
 when appropriate.

 descend from soapbox

 --
 Gregory (Greg) L. Snow Ph.D.
 Statistical Data Center
 Intermountain Healthcare
 greg.s...@imail.org
 801.408.8111

__
R-help@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.


[R] Ordering data by variable

2010-09-02 Thread Mestat

Hi listers,
I could order a data that like this:
x-c(2,6,8,8,1)
y-c(1,6,3,5,4)
o-order(x)
frame-rbind(x,y)[,o]
But, I would like to know if there is a way to order my data without setting
up a data frame. I would like to keep independent vectors x and y.
Any suggestions?
Thanks in advance,
Marcio
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Ordering-data-by-variable-tp2524754p2524754.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Ordering data by variable

2010-09-02 Thread Joshua Wiley
Hi Marcio,

Is this what you want?

x - c(2,6,8,8,1)
y - c(1,6,3,5,4)
o - order(x)

# If you want each vector order by x
x[o]
y[o]

You can also use sort(), but then each vector would be sorted by
itself, not both by x.

HTH,

Josh

On Thu, Sep 2, 2010 at 1:48 PM, Mestat mes...@pop.com.br wrote:

 Hi listers,
 I could order a data that like this:
 x-c(2,6,8,8,1)
 y-c(1,6,3,5,4)
 o-order(x)
 frame-rbind(x,y)[,o]
 But, I would like to know if there is a way to order my data without setting
 up a data frame. I would like to keep independent vectors x and y.
 Any suggestions?
 Thanks in advance,
 Marcio
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Ordering-data-by-variable-tp2524754p2524754.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@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.




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/

__
R-help@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.


Re: [R] Ordering data by variable

2010-09-02 Thread Greg Snow
Suggestion:  use the power of R.

If x and y are independent then sorting y based on x is meaningless.

If sorting y based on x is meaningful, then they are not independent.

Trying to force non-independent things to pretend that they are independent 
just causes future headaches.

Part of the great power of R is the ability to group things together that 
should be grouped.  The wise learn this and use it (in some cases (mine) that 
wisdom comes at the expense of not having properly grouped in the past).

Learn the power of with/within, data= arguments, and apply style functions, 
then you will be eager to combine things into data frames (or lists or ...) 
when appropriate.

descend from soapbox

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of Mestat
 Sent: Thursday, September 02, 2010 2:49 PM
 To: r-help@r-project.org
 Subject: [R] Ordering data by variable
 
 
 Hi listers,
 I could order a data that like this:
 x-c(2,6,8,8,1)
 y-c(1,6,3,5,4)
 o-order(x)
 frame-rbind(x,y)[,o]
 But, I would like to know if there is a way to order my data without
 setting
 up a data frame. I would like to keep independent vectors x and y.
 Any suggestions?
 Thanks in advance,
 Marcio
 --
 View this message in context: http://r.789695.n4.nabble.com/Ordering-
 data-by-variable-tp2524754p2524754.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@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.

__
R-help@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.


[R] ordering data frame

2010-05-05 Thread phoebe kong
Hi all,

I have problem in ordering data frame. Could anyone help me?

 x
 [,1] [,2] [,3]
[1,] A  1  2
[2,] G  3  2
[3,] E  2  3

 y
 [,1] [,2] [,3]
[1,] G  3  3
[2,] A  3  3
[3,] E  3  3

I would like to order data frame x by the order of column 1 of data frame y,
as follow,

 [,1] [,2] [,3]
[1,] G  3  2
[2,] A  1  2
[3,] E  2  3


Thanks,
Phoebe

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] ordering data frame

2010-05-05 Thread Erik Iverson



phoebe kong wrote:

Hi all,

I have problem in ordering data frame. Could anyone help me?


x

 [,1] [,2] [,3]
[1,] A  1  2
[2,] G  3  2
[3,] E  2  3


y

 [,1] [,2] [,3]
[1,] G  3  3
[2,] A  3  3
[3,] E  3  3


Are these really data.frames? They looks like matrices. You do not 
provide ?dput output.




I would like to order data frame x by the order of column 1 of data frame y,
as follow,

 [,1] [,2] [,3]
[1,] G  3  2
[2,] A  1  2
[3,] E  2  3



My example uses data.frames.  ?match and ?order are the important functions.

df1 - data.frame(a = sample(LETTERS[1:5]), b = rnorm(5))
df2 - data.frame(a = sample(LETTERS[1:5]), b = rnorm(5))

df1[order(match(df1$a, df2$a)), ]










Thanks,
Phoebe

[[alternative HTML version deleted]]

__
R-help@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.


__
R-help@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.


[R] ordering columns in a data frame

2010-03-10 Thread Newbie19_02

Dear R users,

I have the following data frame:

 PROCHIdate_admission
2   CAO713 1999-12-11
4   CAO713 1999-10-25
21  CAO0001743 1989-05-04
25  CAO0001743 1996-09-12
26  CAO0001743 1989-05-17
27  CAO0001743 1987-09-17
28  CAO0001743 1987-09-19
29  CAO0001743 1988-01-27
36  CAO0001747 2004-03-21
38  CAO0001747 2004-03-22
39  CAO0001747 2001-02-24
41  CAO0001747 2006-03-31
46  CAO0001901 2007-04-15
61  CAO0002736 2006-05-03
62  CAO0002736 2006-04-05
64  CAO0002736 2006-06-09
65  CAO0002736 2006-04-10
68  CAO0002736 2006-03-14
69  CAO0002736 1995-04-14
72  CAO0002736 1993-11-22
74  CAO0002736 2000-09-26
75  CAO0002736 1995-11-28
77  CAO0003129 1997-05-02
81  CAO0003129 2004-05-08
83  CAO0003129 1998-04-21
85  CAO0003129 1997-04-30
106 CAO0004563 1984-06-10
113 CAO0004563 1984-01-17
153 CAO0012804 1987-02-18
188 CAO0018045 1996-12-04
189 CAO0018045 1996-09-28
291 CAO0030632 1995-04-08
292 CAO0030632 2000-02-10
305 CAO0030632 2007-06-30
306 CAO0030632 2000-07-30
320 CAO0031775 1999-03-05
322 CAO0031775 1992-09-09
323 CAO0031775 1996-07-12
324 CAO0031775 2004-09-12
325 CAO0031775 1998-01-17
328 CAO0031775 1999-02-25
329 CAO0031775 1999-02-26
330 CAO0031775 1999-02-27
331 CAO0031775 2006-03-29
377 CAO0034275 1990-10-05
382 CAO0039712 1982-11-01
387 CAO0039712 2003-01-10
389 CAO0039712 1982-07-13
390 CAO0039712 1996-05-14
393 CAO0039712 1982-07-15
396 CAO0039712 1982-06-20
397 CAO0039712 1982-06-22
399 CAO0039712 1996-07-24
400 CAO0039712 1996-01-26
401 CAO0039712 1996-04-29
427 CAO0045125 1999-02-02
429 CAO0045125 2000-11-04
430 CAO0045125 1998-06-05
431 CAO0045125 1998-06-07
433 CAO0045125 1989-10-09
434 CAO0045125 1989-10-10
435 CAO0045125 1989-09-11
437 CAO0045125 1989-09-13
441 CAO0045125 1999-03-22
444 CAO0045125 1989-09-29
445 CAO0045125 2006-01-31
452 CAO0048575 2006-01-02
453 CAO0048575 2006-01-04
454 CAO0048856 1994-10-06
456 CAO0048856 1994-10-12
461 CAO0048856 1994-03-28
464 CAO0050041 2007-03-01
466 CAO0050041 2007-04-04
481 CAO0050041 2007-07-10
490 CAO0050041 1996-07-16
510 CAO0050041 2003-11-25
514 CAO0050041 2004-05-26
520 CAO0050041 2006-10-29
531 CAO0055131 1993-04-03
533 CAO0055131 1994-07-22
535 CAO0055131 1994-01-31
538 CAO0056636 1997-12-02
550 CAO0059403 1985-12-08
552 CAO0059403 2005-05-12
556 CAO0059403 1985-08-31
559 CAO0059680 2005-05-02
564 CAO0059680 2002-12-05
582 CAO0059680 2003-09-16
585 CAO0059680 1997-04-18
586 CAO0059680 2007-06-18
589 CAO0059680 2005-03-20
659 CAO0065288 2006-07-01
682 CAO0070694 2007-09-13
685 CAO0070694 2006-08-22
695 CAO0072477 2003-06-04
696 CAO0072477 2004-07-05
718 CAO0073505 1998-09-15
720 CAO0073505 1989-09-18
725 CAO0073505 2000-11-22
727 CAO0073505 1991-08-23

I have managed to order it by PROCHI number using orderBy(PROCHI, data=dd) 
what I need to do is order by PROCHI then by date of admission so that date
of admission is ascending by PROCHI ascending.  

 PROCHIdate_admission
2   CAO713  1999-10-25
4   CAO713  1999-12-11
21  CAO0001743 1987-09-17
25  CAO0001743 1989-05-04
26  CAO0001743 1989-05-17
27  CAO0001743 1996-09-12

I've also had a look at order using the following commands:

Just the straight dd[order(dd$PROCHI, dd$date_admission) ,]
and dd[ do.call(order, dd) ,]

but I'm not sure how I can achieve what I need.  

Thanks,
Natalie
-- 
View this message in context: 
http://n4.nabble.com/ordering-columns-in-a-data-frame-tp1587294p1587294.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] ordering columns in a data frame

2010-03-10 Thread David Freedman

I'm not sure what's incorrect about your result, but the following works:
d=data.frame(a=sample(letters[1:5],10,rep=T),b=rnorm(10),c=sample(1:10,10));
d
d[order(d$a,d$c),]

or, you can use orderBy:
lib(doBy)
orderBy(~a+b,data=d)  #use a - sign to sort in descending sequence

Did you leave off the tilde in your orderBy example?

hth
David Freedman, CDC Atlanta
-- 
View this message in context: 
http://n4.nabble.com/ordering-columns-in-a-data-frame-tp1587294p1587318.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] ordering columns in a data frame

2010-03-10 Thread Newbie19_02

Thanks David. Leaving off the tilde was the problem.  
-- 
View this message in context: 
http://n4.nabble.com/ordering-columns-in-a-data-frame-tp1587294p1587491.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


[R] Ordering categories on a boxplot - a serious trap??

2010-02-25 Thread Schwab,Wilhelm K
Hello all,

I think I probably did something stupid, and R's part was to allow me to do it. 
 My goal was to control the order of factor levels appearing horizontally on a 
boxplot.  Enter search engines and perhaps some creative stupidity on my part, 
and I came up with the following:

v=read.table(factor-order.txt,header=TRUE);
levels(v$doseGroup) = c(L, M, H);
boxplot(v$dose~v$doseGroup);


A good way to see the trap is to evaluate:

v=read.table(factor-order.txt,header=TRUE);
par(mfrow=c(2,1));
boxplot(v$dose~v$doseGroup);
levels(v$doseGroup) = c(L, M, H);
boxplot(v$dose~v$doseGroup);
par(mfrow=c(1,1));

The above creates two plots, one correct with the factors in an inconvient 
order, and one that is WRONG.  In the latter, the labels appear in the desired 
order, but the data does not move with them.  I did not discover the problem 
until I repeated the same type of plot with something that had a known 
relationship with the levels, and the result was clearly not correct.

I *think* the problem is to assign to the return value of levels().  How did I 
think to do that?  I'm not really sure, but please look at

  https://stat.ethz.ch/pipermail/r-help/2008-August/171884.html


Perhaps it does not say to do exactly what I did, but it sure was easy to 
follow to the mistake, it appeared to do what I wanted, and the consequences of 
the mistake are ugly.  Perhaps levels() should return something that is 
immutable??  If I am looking at this correctly, levels() is an accident waiting 
to happen.

What should I have done?  It seems:

read data and order factor levels
v=read.table(factor-order.txt,header=TRUE);
group = factor(v$doseGroup,levels = c(L, M, H) );
boxplot(v$dose~group);


One disappointment is that the above factor() call apparently needs to be 
repeated for any subset of v - I'm still trying to get my mind around that one.

Can anyone confirm this?  It strikes me as a trap that should be addressed so 
that an error results rather than a garbage graph.

Bill


---
Wilhelm K. Schwab, Ph.D.

__
R-help@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.


Re: [R] Ordering categories on a boxplot - a serious trap??

2010-02-25 Thread William Dunlap
 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Schwab,Wilhelm K
 Sent: Thursday, February 25, 2010 3:51 PM
 To: r-help@r-project.org
 Subject: [R] Ordering categories on a boxplot - a serious trap??
 
 Hello all,
 
 I think I probably did something stupid, and R's part was to 
 allow me to do it.  My goal was to control the order of 
 factor levels appearing horizontally on a boxplot.  Enter 
 search engines and perhaps some creative stupidity on my 
 part, and I came up with the following:
 
   v=read.table(factor-order.txt,header=TRUE);
   levels(v$doseGroup) = c(L, M, H);
   boxplot(v$dose~v$doseGroup);

levels- translated the current level labels into
another language, it did not change the integer
codes of the factor.  If you want to reorder the
levels call factor(..., levels=).  E.g.,

   z - factor(c(Small,Large,Medium,Small))
   str(z)
   Factor w/ 3 levels Large,Medium,..: 3 1 2 3
   str(factor(z, levels=c(Small,Medium,Large)))
   Factor w/ 3 levels Small,Medium,..: 1 3 2 1

You can relabel them also by using the labels= argument
to factor
   str(factor(z, levels=c(Small,Medium,Large),
labels=c(S,M,L)))
 Factor w/ 3 levels S,M,L: 1 3 2 1

Calling levels- changes nothing but the level labels:
   zcopy - z
   levels(zcopy) - c(Small,Medium,Large)
   str(zcopy)
Factor w/ 3 levels Small,Medium,..: 3 1 2 3

levels- is handy for low-level manipulations but not
for general use.  Even factor(,levels=) can be a bit
dangerous: if a new level is misspelled it will silently
add NA's to the data:
   str(factor(z, levels=c(Smal, Medium, Large)))
   Factor w/ 3 levels Smal,Medium,..: NA 3 2 NA

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

 
 
 A good way to see the trap is to evaluate:
 
   v=read.table(factor-order.txt,header=TRUE);
   par(mfrow=c(2,1));
   boxplot(v$dose~v$doseGroup);
   levels(v$doseGroup) = c(L, M, H);
   boxplot(v$dose~v$doseGroup);
   par(mfrow=c(1,1));
 
 The above creates two plots, one correct with the factors in 
 an inconvient order, and one that is WRONG.  In the latter, 
 the labels appear in the desired order, but the data does not 
 move with them.  I did not discover the problem until I 
 repeated the same type of plot with something that had a 
 known relationship with the levels, and the result was 
 clearly not correct.
 
 I *think* the problem is to assign to the return value of 
 levels().  How did I think to do that?  I'm not really sure, 
 but please look at
 
   https://stat.ethz.ch/pipermail/r-help/2008-August/171884.html
 
 
 Perhaps it does not say to do exactly what I did, but it sure 
 was easy to follow to the mistake, it appeared to do what I 
 wanted, and the consequences of the mistake are ugly.  
 Perhaps levels() should return something that is immutable??  
 If I am looking at this correctly, levels() is an accident 
 waiting to happen.
 
 What should I have done?  It seems:
 
   read data and order factor levels
   v=read.table(factor-order.txt,header=TRUE);
   group = factor(v$doseGroup,levels = c(L, M, H) );
   boxplot(v$dose~group);
 
 
 One disappointment is that the above factor() call apparently 
 needs to be repeated for any subset of v - I'm still trying 
 to get my mind around that one.
 
 Can anyone confirm this?  It strikes me as a trap that should 
 be addressed so that an error results rather than a garbage graph.
 
 Bill
 
 
 ---
 Wilhelm K. Schwab, Ph.D.
 
 __
 R-help@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.
 

__
R-help@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.


Re: [R] Ordering categories on a boxplot - a serious trap??

2010-02-25 Thread Schwab,Wilhelm K
Phil,

That works[*], but I still think there is a big problem given how easy it is to 
do the wrong thing, and that searches lead to dangerous instructions.  
Hopefully this will serve to keep others out of trouble, but so might an 
immutable return value from levels().

[*] I have not yet done anything with selecting parts of the data frame.  Using 
a separate factor, I quickly hit trouble with size mismatches, though I could 
probably work around them by recreating the factor after any such change.  
Proceeding with caution...

Bill

---
Wilhelm K. Schwab, Ph.D.



-Original Message-
From: Phil Spector [mailto:spec...@stat.berkeley.edu]
Sent: Thursday, February 25, 2010 7:06 PM
To: Schwab,Wilhelm K
Subject: Re: [R] Ordering categories on a boxplot - a serious trap??

Wilhelm -
I don't know if this is correct for your problem because you didn't provide 
a reproducible example, but perhaps you could try

v$doseGroup = factor(v$doseGroup,levels=c(L, M, H))

instead of setting the levels directly.

- Phil Spector
 Statistical Computing Facility
 Department of Statistics
 UC Berkeley
 spec...@stat.berkeley.edu

On Thu, 25 Feb 2010, Schwab,Wilhelm K wrote:

 Hello all,

 I think I probably did something stupid, and R's part was to allow me to do 
 it.  My goal was to control the order of factor levels appearing horizontally 
 on a boxplot.  Enter search engines and perhaps some creative stupidity on my 
 part, and I came up with the following:

   v=read.table(factor-order.txt,header=TRUE);
   levels(v$doseGroup) = c(L, M, H);
   boxplot(v$dose~v$doseGroup);


 A good way to see the trap is to evaluate:

   v=read.table(factor-order.txt,header=TRUE);
   par(mfrow=c(2,1));
   boxplot(v$dose~v$doseGroup);
   levels(v$doseGroup) = c(L, M, H);
   boxplot(v$dose~v$doseGroup);
   par(mfrow=c(1,1));

 The above creates two plots, one correct with the factors in an inconvient 
 order, and one that is WRONG.  In the latter, the labels appear in the 
 desired order, but the data does not move with them.  I did not discover 
 the problem until I repeated the same type of plot with something that had a 
 known relationship with the levels, and the result was clearly not correct.

 I *think* the problem is to assign to the return value of levels().  
 How did I think to do that?  I'm not really sure, but please look at

  https://stat.ethz.ch/pipermail/r-help/2008-August/171884.html


 Perhaps it does not say to do exactly what I did, but it sure was easy to 
 follow to the mistake, it appeared to do what I wanted, and the consequences 
 of the mistake are ugly.  Perhaps levels() should return something that is 
 immutable??  If I am looking at this correctly, levels() is an accident 
 waiting to happen.

 What should I have done?  It seems:

   read data and order factor levels
   v=read.table(factor-order.txt,header=TRUE);
   group = factor(v$doseGroup,levels = c(L, M, H) );
   boxplot(v$dose~group);


 One disappointment is that the above factor() call apparently needs to be 
 repeated for any subset of v - I'm still trying to get my mind around that 
 one.

 Can anyone confirm this?  It strikes me as a trap that should be addressed so 
 that an error results rather than a garbage graph.

 Bill


 ---
 Wilhelm K. Schwab, Ph.D.

 __
 R-help@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.


__
R-help@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.


Re: [R] Ordering categories on a boxplot - a serious trap??

2010-02-25 Thread Ista Zahn
Hi Wilhelm,
I agree it's confusing to have a levels() function that does something
so different from the levels argument of the factor function.
Personally I use levels() only as an extractor, never to change
levels. For that I use factor(), with the levels and labels arguments
as needed.

Best,
Ista

On Thu, Feb 25, 2010 at 8:40 PM, Schwab,Wilhelm K bsch...@anest.ufl.edu wrote:
 Phil,

 That works[*], but I still think there is a big problem given how easy it is 
 to do the wrong thing, and that searches lead to dangerous instructions.  
 Hopefully this will serve to keep others out of trouble, but so might an 
 immutable return value from levels().

 [*] I have not yet done anything with selecting parts of the data frame.  
 Using a separate factor, I quickly hit trouble with size mismatches, though I 
 could probably work around them by recreating the factor after any such 
 change.  Proceeding with caution...

 Bill

 ---
 Wilhelm K. Schwab, Ph.D.



 -Original Message-
 From: Phil Spector [mailto:spec...@stat.berkeley.edu]
 Sent: Thursday, February 25, 2010 7:06 PM
 To: Schwab,Wilhelm K
 Subject: Re: [R] Ordering categories on a boxplot - a serious trap??

 Wilhelm -
    I don't know if this is correct for your problem because you didn't 
 provide a reproducible example, but perhaps you could try

 v$doseGroup = factor(v$doseGroup,levels=c(L, M, H))

 instead of setting the levels directly.

                                        - Phil Spector
                                         Statistical Computing Facility
                                         Department of Statistics
                                         UC Berkeley
                                         spec...@stat.berkeley.edu

 On Thu, 25 Feb 2010, Schwab,Wilhelm K wrote:

 Hello all,

 I think I probably did something stupid, and R's part was to allow me to do 
 it.  My goal was to control the order of factor levels appearing 
 horizontally on a boxplot.  Enter search engines and perhaps some creative 
 stupidity on my part, and I came up with the following:

       v=read.table(factor-order.txt,header=TRUE);
       levels(v$doseGroup) = c(L, M, H);
       boxplot(v$dose~v$doseGroup);


 A good way to see the trap is to evaluate:

       v=read.table(factor-order.txt,header=TRUE);
       par(mfrow=c(2,1));
       boxplot(v$dose~v$doseGroup);
       levels(v$doseGroup) = c(L, M, H);
       boxplot(v$dose~v$doseGroup);
       par(mfrow=c(1,1));

 The above creates two plots, one correct with the factors in an inconvient 
 order, and one that is WRONG.  In the latter, the labels appear in the 
 desired order, but the data does not move with them.  I did not discover 
 the problem until I repeated the same type of plot with something that had a 
 known relationship with the levels, and the result was clearly not correct.

 I *think* the problem is to assign to the return value of levels().
 How did I think to do that?  I'm not really sure, but please look at

  https://stat.ethz.ch/pipermail/r-help/2008-August/171884.html


 Perhaps it does not say to do exactly what I did, but it sure was easy to 
 follow to the mistake, it appeared to do what I wanted, and the consequences 
 of the mistake are ugly.  Perhaps levels() should return something that is 
 immutable??  If I am looking at this correctly, levels() is an accident 
 waiting to happen.

 What should I have done?  It seems:

       read data and order factor levels
       v=read.table(factor-order.txt,header=TRUE);
       group = factor(v$doseGroup,levels = c(L, M, H) );
       boxplot(v$dose~group);


 One disappointment is that the above factor() call apparently needs to be 
 repeated for any subset of v - I'm still trying to get my mind around that 
 one.

 Can anyone confirm this?  It strikes me as a trap that should be addressed 
 so that an error results rather than a garbage graph.

 Bill


 ---
 Wilhelm K. Schwab, Ph.D.

 __
 R-help@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.


 __
 R-help@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.




-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

__
R-help@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.


[R] ordering of additional columns in forest plot in meta package

2010-01-10 Thread Philip de Witt Hamer
Hi,

I am trying to add additional columns to a forest plot using the meta package.
The study information and subgroup analysis plotting is handled properly.
For this output the data is ordered first by subgroup label
(rnd.subgroup1 in the example) and second decreasing size of totals
('n' in the example).
The proper ordering of this data is confirmed by the color coding
(black and red in the example) of the subgroup label. Also the
studlab,event and n are all ordered correctly.

The probIem now is that I cannot get the added columns
(rnd.subgroup1 and rnd.subgroup2) to follow this same proper
ordering.

library(meta)
# dummy data
nr.studies - 20
rnd.subgroup1  - round(rnorm(nr.studies,1.5,.1),0) # random 1s and 2s
rnd.subgroup2  - c(letters[1:nr.studies]) # ordered unique letters
lbls   - c(letters[1:nr.studies]) # letters as surrogate study
labels 'author et al, year'
event  - round(rnorm(nr.studies,10,5),0) # random event nrs
event[event0]-0 # to avoid a negative value error
n  - round(rnorm(nr.studies,100,25),0) # random totals
mydata - 
data.frame(cbind(lbls,rnd.subgroup1,rnd.subgroup2,rnd.subgroup3,event,n))
mydata
a - metaprop(event,n,studlab=lbls)
a$rnd.subgroup1 - addvar(a,mydata,rnd.subgroup1,by.y=lbls)
a$rnd.subgroup2 - addvar(a,mydata,rnd.subgroup2,by.y=lbls)
grid.newpage()
forest(a,
studlab=lbls,
comb.fixed=T,comb.random=F,overall=T,
text.fixed=my title here,
byvar=rnd.subgroup1,
print.byvar=T,
leftcols=c(studlab,rnd.subgroup1,rnd.subgroup2,event,n), #
sort order not right for 'rnd.subgroup1' and 'rnd.subgroup2'
bylab=c(one,two),
sortvar=-n,
col.i=rnd.subgroup1,
col.by=c(royalblue),
xlim=c(0,.5)
)

I suspect that it may have to do with an omitted indexing command in
the forest function.
Your input in kindly appreciated.

Philip de Witt Hamer, MD PhD

VU medical center
dept neurosurgery
PO Box 7057
1007 MB Amsterdam
The Netherlands

__
R-help@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.


Re: [R] Ordering variables in a parallel coordinates plot

2010-01-03 Thread Charles C. Berry

On Sat, 2 Jan 2010, Tal Galili wrote:


Hello all,

I am searching for a way in R to re-order variables before presenting them
in a parallel coordinates plot.

So far I didn't find anything within a R related context on how to do this.
I did find some texts talking about how it should be done in general, here
is such example:
http://tinyurl.com/ycnsjpe

Is there a package or an example of the variable ordering (for parallel
coordinate plot) in R ?


Follow the posting guide

??parallel
library(MASS)
?parcoord
example( parcoord )

See the last line of the example.

HTH,

Chuck



Thanks,
Tal


Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com/ (English)
--

[[alternative HTML version deleted]]

__
R-help@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.



Charles C. Berry(858) 534-2098
Dept of Family/Preventive Medicine
E mailto:cbe...@tajo.ucsd.edu   UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

__
R-help@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.


Re: [R] Ordering variables in a parallel coordinates plot

2010-01-03 Thread Tal Galili
Hi Charles,
Thanks for answering - you are right about the posting guide (sorry).

In any case, my question wasn't on how to reorder the columns (that is
simple), but on how to choose what order to put them in.


Thanks,
Tal



Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com/ (English)
--




On Sun, Jan 3, 2010 at 7:05 PM, Charles C. Berry cbe...@tajo.ucsd.eduwrote:

 On Sat, 2 Jan 2010, Tal Galili wrote:

  Hello all,

 I am searching for a way in R to re-order variables before presenting them
 in a parallel coordinates plot.

 So far I didn't find anything within a R related context on how to do
 this.
 I did find some texts talking about how it should be done in general, here
 is such example:
 http://tinyurl.com/ycnsjpe

 Is there a package or an example of the variable ordering (for parallel
 coordinate plot) in R ?


 Follow the posting guide

??parallel
library(MASS)
?parcoord
example( parcoord )

 See the last line of the example.

 HTH,

 Chuck


 Thanks,
 Tal


 Contact
 Details:---
 Contact me: tal.gal...@gmail.com |  972-52-7275845
 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
 www.r-statistics.com/ (English)

 --

[[alternative HTML version deleted]]


 __
 R-help@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.


 Charles C. Berry(858) 534-2098
Dept of Family/Preventive
 Medicine
 E mailto:cbe...@tajo.ucsd.edu   UC San Diego
 http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901




[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Ordering variables in a parallel coordinates plot

2010-01-03 Thread Tal Galili
Hi Charles,

You're solution is great (and is actually what my professor suggested me to
do today).

In the meantime I searched even more and found this article:
http://davis.wpi.edu/~xmdv/docs/tr0313_osf.pdf

That gives a good description of the problem and of his attempts at solving
it.
I started by implementing (in a very rough way) the solution of all
possible combinations, but it is not relevant for more then 7 dimensions.
His solution will involve a mix of your solution with a local optimum, but I
don't think I will go more into solving it anytime soon (but instead, make
due with your solution).

Thanks again,
Tal















Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com/ (English)
--




On Sun, Jan 3, 2010 at 10:05 PM, Charles C. Berry cbe...@tajo.ucsd.eduwrote:

 On Sun, 3 Jan 2010, Tal Galili wrote:

  Hi Charles,
 Thanks for answering - you are right about the posting guide (sorry).

 In any case, my question wasn't on how to reorder the columns (that is
 simple), but on how to choose what order to put them in.



 OK, and I see you included a reference, so there is probably more to this
 than meets my eye.

 But would something as simple as this be good enough??

  library(MASS)
 hc1 - hclust(dist(cor(log(iris[, 1:4]
 parcoord(log(ir)[,  hc1$order ], col = 1 + (0:149)%/%50)


 or possibly

hc1 - hclust(dist( abs( cor(log(iris[, 1:4])


 Chuck



 Thanks,
 Tal



 Contact
 Details:---
 Contact me: tal.gal...@gmail.com |  972-52-7275845
 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
 www.r-statistics.com/ (English)

 --




 On Sun, Jan 3, 2010 at 7:05 PM, Charles C. Berry cbe...@tajo.ucsd.edu
 wrote:

  On Sat, 2 Jan 2010, Tal Galili wrote:

  Hello all,


 I am searching for a way in R to re-order variables before presenting
 them
 in a parallel coordinates plot.

 So far I didn't find anything within a R related context on how to do
 this.
 I did find some texts talking about how it should be done in general,
 here
 is such example:
 http://tinyurl.com/ycnsjpe

 Is there a package or an example of the variable ordering (for parallel
 coordinate plot) in R ?


 Follow the posting guide

   ??parallel
   library(MASS)
   ?parcoord
   example( parcoord )

 See the last line of the example.

 HTH,

 Chuck


  Thanks,
 Tal


 Contact
 Details:---
 Contact me: tal.gal...@gmail.com |  972-52-7275845
 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew)
 |
 www.r-statistics.com/ (English)


 --

   [[alternative HTML version deleted]]


 __
 R-help@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.


  Charles C. Berry(858) 534-2098
   Dept of Family/Preventive
 Medicine
 E mailto:cbe...@tajo.ucsd.edu   UC San Diego
 http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego
 92093-0901




[[alternative HTML version deleted]]

 __
 R-help@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.


 Charles C. Berry(858) 534-2098
Dept of Family/Preventive
 Medicine
 E mailto:cbe...@tajo.ucsd.edu   UC San Diego
 http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901




[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Ordering variables in a parallel coordinates plot

2010-01-03 Thread Charles C. Berry

On Sun, 3 Jan 2010, Tal Galili wrote:


Hi Charles,
Thanks for answering - you are right about the posting guide (sorry).

In any case, my question wasn't on how to reorder the columns (that is
simple), but on how to choose what order to put them in.



OK, and I see you included a reference, so there is probably more to this 
than meets my eye.


But would something as simple as this be good enough??


library(MASS)
hc1 - hclust(dist(cor(log(iris[, 1:4]
parcoord(log(ir)[,  hc1$order ], col = 1 + (0:149)%/%50)


or possibly

hc1 - hclust(dist( abs( cor(log(iris[, 1:4])

Chuck




Thanks,
Tal



Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com/ (English)
--




On Sun, Jan 3, 2010 at 7:05 PM, Charles C. Berry cbe...@tajo.ucsd.eduwrote:


On Sat, 2 Jan 2010, Tal Galili wrote:

 Hello all,


I am searching for a way in R to re-order variables before presenting them
in a parallel coordinates plot.

So far I didn't find anything within a R related context on how to do
this.
I did find some texts talking about how it should be done in general, here
is such example:
http://tinyurl.com/ycnsjpe

Is there a package or an example of the variable ordering (for parallel
coordinate plot) in R ?



Follow the posting guide

   ??parallel
   library(MASS)
   ?parcoord
   example( parcoord )

See the last line of the example.

HTH,

Chuck



Thanks,
Tal


Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com/ (English)

--

   [[alternative HTML version deleted]]


__
R-help@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.



Charles C. Berry(858) 534-2098
   Dept of Family/Preventive
Medicine
E mailto:cbe...@tajo.ucsd.edu   UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901





[[alternative HTML version deleted]]

__
R-help@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.



Charles C. Berry(858) 534-2098
Dept of Family/Preventive Medicine
E mailto:cbe...@tajo.ucsd.edu   UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

__
R-help@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.


Re: [R] Ordering variables in a parallel coordinates plot

2010-01-03 Thread Dieter Menne

Hi, Tal,


Tal Galili wrote:
 
 In any case, my question wasn't on how to reorder the columns (that is
 simple), but on how to choose what order to put them in.
 

So is your question answered? Or what exactly is the problem using the
example below?

library(lattice)
parallel(~iris[1:4] | Species, iris) 
# if I understand you, this is easy
parallel(~iris[c(3,2,1,4)] | Species, iris) 

# so I only can think you mean this...
iris$SpeciesR =  with(iris, 
  factor(Species,levels= levels(Species)[c(3,1,2)]))
parallel(~iris[1:4] | SpeciesR, iris) 
# .. but I am sure you know this already


Dieter

-- 
View this message in context: 
http://n4.nabble.com/Ordering-variables-in-a-parallel-coordinates-plot-tp997388p997909.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


[R] Ordering variables in a parallel coordinates plot

2010-01-02 Thread Tal Galili
Hello all,

I am searching for a way in R to re-order variables before presenting them
in a parallel coordinates plot.

So far I didn't find anything within a R related context on how to do this.
I did find some texts talking about how it should be done in general, here
is such example:
http://tinyurl.com/ycnsjpe

Is there a package or an example of the variable ordering (for parallel
coordinate plot) in R ?

Thanks,
Tal


Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com/ (English)
--

[[alternative HTML version deleted]]

__
R-help@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.


[R] Ordering numbers

2009-12-02 Thread Lisa

Hello all,

I have a set of numbers that looks like this:

 id - c(1, 1, 2, 2, 2, 3, 4, 4, 4, 4, 1, 2, 2, 2, 3, 3, 1, 1, 1, 2, 3, 4,
 4, 4, 5, 5)
 id
 [1] 1 1 2 2 2 3 4 4 4 4 1 2 2 2 3 3 1 1 1 2 3 4 4 4 5 5

Please ignore the bold numbers, I just want to make my problem clear.
I am going to order them as this:

1 1 2 2 2 3 4 4 4 4 5 6 6 6 7 7 8 8 8 9 10 11 11 11 12 12

Can anyone please help how to get this done? Your help would be greatly
appreciated. 

Lisa 

-- 
View this message in context: 
http://n4.nabble.com/Ordering-numbers-tp941453p941453.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] Ordering numbers

2009-12-02 Thread Senthil Kumar M
On Wed, Dec 2, 2009 at 3:30 PM, Lisa lisa...@gmail.com wrote:

 Hello all,

 I have a set of numbers that looks like this:

 id - c(1, 1, 2, 2, 2, 3, 4, 4, 4, 4, 1, 2, 2, 2, 3, 3, 1, 1, 1, 2, 3, 4,
 4, 4, 5, 5)
 id
  [1] 1 1 2 2 2 3 4 4 4 4 1 2 2 2 3 3 1 1 1 2 3 4 4 4 5 5

 Please ignore the bold numbers, I just want to make my problem clear.
 I am going to order them as this:

 1 1 2 2 2 3 4 4 4 4 5 6 6 6 7 7 8 8 8 9 10 11 11 11 12 12

 Can anyone please help how to get this done? Your help would be greatly
 appreciated.

 Lisa


Hi,

?sort

 sort(id)
 [1] 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 4 4 4 4 4 4 4 5 5

Senthil

__
R-help@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.


Re: [R] Ordering numbers

2009-12-02 Thread Greg Snow
Here is one way:

 id - c(1, 1, 2, 2, 2, 3, 4, 4, 4, 4, 1, 2, 2, 2, 3, 3, 1, 1, 1, 2, 3, 4,
+ 4, 4, 5, 5)
 id
 [1] 1 1 2 2 2 3 4 4 4 4 1 2 2 2 3 3 1 1 1 2 3 4 4 4 5 5
 tmp - rle(id)
 tmp
Run Length Encoding
  lengths: int [1:12] 2 3 1 4 1 3 2 3 1 1 ...
  values : num [1:12] 1 2 3 4 1 2 3 1 2 3 ...
 rep( seq_along(tmp$lengths), tmp$lengths )
 [1]  1  1  2  2  2  3  4  4  4  4  5  6  6  6  7  7  8  8  8  9 10 11 11 11 12
[26] 12

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of Lisa
 Sent: Wednesday, December 02, 2009 1:30 PM
 To: r-help@r-project.org
 Subject: [R] Ordering numbers
 
 
 Hello all,
 
 I have a set of numbers that looks like this:
 
  id - c(1, 1, 2, 2, 2, 3, 4, 4, 4, 4, 1, 2, 2, 2, 3, 3, 1, 1, 1, 2,
 3, 4,
  4, 4, 5, 5)
  id
  [1] 1 1 2 2 2 3 4 4 4 4 1 2 2 2 3 3 1 1 1 2 3 4 4 4 5 5
 
 Please ignore the bold numbers, I just want to make my problem clear.
 I am going to order them as this:
 
 1 1 2 2 2 3 4 4 4 4 5 6 6 6 7 7 8 8 8 9 10 11 11 11 12 12
 
 Can anyone please help how to get this done? Your help would be greatly
 appreciated.
 
 Lisa
 
 --
 View this message in context: http://n4.nabble.com/Ordering-numbers-
 tp941453p941453.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@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.

__
R-help@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.


Re: [R] Ordering numbers

2009-12-02 Thread Greg Snow
Your output does not match the requested output, I think the original poster 
may have used the word order differently than how you are thinking.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of Senthil Kumar M
 Sent: Wednesday, December 02, 2009 1:36 PM
 To: Lisa
 Cc: r-help@r-project.org
 Subject: Re: [R] Ordering numbers
 
 On Wed, Dec 2, 2009 at 3:30 PM, Lisa lisa...@gmail.com wrote:
 
  Hello all,
 
  I have a set of numbers that looks like this:
 
  id - c(1, 1, 2, 2, 2, 3, 4, 4, 4, 4, 1, 2, 2, 2, 3, 3, 1, 1, 1, 2,
 3, 4,
  4, 4, 5, 5)
  id
   [1] 1 1 2 2 2 3 4 4 4 4 1 2 2 2 3 3 1 1 1 2 3 4 4 4 5 5
 
  Please ignore the bold numbers, I just want to make my problem clear.
  I am going to order them as this:
 
  1 1 2 2 2 3 4 4 4 4 5 6 6 6 7 7 8 8 8 9 10 11 11 11 12 12
 
  Can anyone please help how to get this done? Your help would be
 greatly
  appreciated.
 
  Lisa
 
 
 Hi,
 
 ?sort
 
  sort(id)
  [1] 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 4 4 4 4 4 4 4 5 5
 
 Senthil
 
 __
 R-help@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.

__
R-help@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.


Re: [R] Ordering numbers

2009-12-02 Thread Peter Dalgaard

Greg Snow wrote:

Here is one way:


id - c(1, 1, 2, 2, 2, 3, 4, 4, 4, 4, 1, 2, 2, 2, 3, 3, 1, 1, 1, 2, 3, 4,

+ 4, 4, 5, 5)

id

 [1] 1 1 2 2 2 3 4 4 4 4 1 2 2 2 3 3 1 1 1 2 3 4 4 4 5 5

tmp - rle(id)
tmp

Run Length Encoding
  lengths: int [1:12] 2 3 1 4 1 3 2 3 1 1 ...
  values : num [1:12] 1 2 3 4 1 2 3 1 2 3 ...

rep( seq_along(tmp$lengths), tmp$lengths )

 [1]  1  1  2  2  2  3  4  4  4  4  5  6  6  6  7  7  8  8  8  9 10 11 11 11 12
[26] 12



Here's another:


 d - diff(c(0,id))
 d[d0] - 1
 cumsum(d)
 [1]  1  1  2  2  2  3  4  4  4  4  5  6  6  6  7  7  8  8  8  9 10 11 
11 11 12

[26] 12

--
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - (p.dalga...@biostat.ku.dk)  FAX: (+45) 35327907

__
R-help@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.


Re: [R] Ordering numbers

2009-12-02 Thread William Dunlap
 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Lisa
 Sent: Wednesday, December 02, 2009 12:30 PM
 To: r-help@r-project.org
 Subject: [R] Ordering numbers
 
 
 Hello all,
 
 I have a set of numbers that looks like this:
 
  id - c(1, 1, 2, 2, 2, 3, 4, 4, 4, 4, 1, 2, 2, 2, 3, 3, 1, 
 1, 1, 2, 3, 4,
  4, 4, 5, 5)
  id
  [1] 1 1 2 2 2 3 4 4 4 4 1 2 2 2 3 3 1 1 1 2 3 4 4 4 5 5
 
 Please ignore the bold numbers, I just want to make my problem clear.
 I am going to order them as this:
 
 1 1 2 2 2 3 4 4 4 4 5 6 6 6 7 7 8 8 8 9 10 11 11 11 12 12

Do you want to assign a run identification number to each value?
If so try
c(1,cumsum(id[-1]!=id[-length(id)])+1)
[1]  1  1  2  2  2  3  4  4  4  4  5  6  6  6  7  7  8  8  8  9 10
11 11 11 12 12
or the equivalent
r-rle(id)
rep(seq_along(r$lengths), r$lengths)
[1]  1  1  2  2  2  3  4  4  4  4  5  6  6  6  7  7  8  8  8  9 10
11 11 11 12 12
(cumsum(x[-1]!=x[-length(x)] is part of the rle algorithm.)

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com  


 Can anyone please help how to get this done? Your help would 
 be greatly
 appreciated. 
 
 Lisa 
 
 -- 
 View this message in context: 
 http://n4.nabble.com/Ordering-numbers-tp941453p941453.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@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.
 

__
R-help@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.


Re: [R] ordering and factors into column headings

2009-09-02 Thread Henrique Dallazuanna
Try this also:

xtabs(value ~ site + parameter, data = DF)

On Tue, Sep 1, 2009 at 8:59 PM, Krista Chin 0574...@acadiau.ca wrote:

 Hi,

 The lab in which I send my samples return the results in a format that
 is difficult for me to run my analysis.  The lab outputs the results
 where each parameter is its own row and it’s not consistently in the
 same order (and not each sample is tested for the same suite of
 variables).

 e.g.

 dataset

 siteparameter  value
 a   e2  3
 a   e1  1
 a   e3  5
 b   e3  1
 b   e1  2
 c   e5  4
 c   e4  5
 c   e2  2
 d   e2  4
 d   e4  3
 e   e1  2

 How would I go about transforming the above table to the one below,
 where each parameter has its own column and there is only 1 row of data
 for each site?

 sitee1  e2  e3  e4  e5
 a   1   3   5   NA  NA
 b   2   NA  3   NA  NA
 c   NA  2   NA  5   4
 d   NA  4   NA  3   NA
 e   2   NA  NA  NA  NA

 I have attempted to write a loop and use the “match” function, but
 it kept getting more and more complicated.  I have a feeling that there
 is simple solution, but I just don’t see it.

 Any insight would be helpful.

 Thanks,
 Krista

[[alternative HTML version deleted]]


 __
 R-help@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.




-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

[[alternative HTML version deleted]]

__
R-help@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.


[R] ordering and factors into column headings

2009-09-01 Thread Krista Chin
Hi,

The lab in which I send my samples return the results in a format that
is difficult for me to run my analysis.  The lab outputs the results
where each parameter is its own row and it’s not consistently in the
same order (and not each sample is tested for the same suite of
variables).

e.g.

dataset

siteparameter  value
a   e2  3
a   e1  1
a   e3  5
b   e3  1
b   e1  2
c   e5  4
c   e4  5
c   e2  2
d   e2  4
d   e4  3
e   e1  2

How would I go about transforming the above table to the one below,
where each parameter has its own column and there is only 1 row of data
for each site?

sitee1  e2  e3  e4  e5
a   1   3   5   NA  NA
b   2   NA  3   NA  NA
c   NA  2   NA  5   4
d   NA  4   NA  3   NA
e   2   NA  NA  NA  NA

I have attempted to write a loop and use the “match” function, but
it kept getting more and more complicated.  I have a feeling that there
is simple solution, but I just don’t see it.

Any insight would be helpful.

Thanks,
Krista

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] ordering and factors into column headings

2009-09-01 Thread Gabor Grothendieck
Try the reshape package:

 library(reshape)
 cast(DF, site ~ parameter)
  site e1 e2 e3 e4 e5
1a  1  3  5 NA NA
2b  2 NA  1 NA NA
3c NA  2 NA  5  4
4d NA  4 NA  3 NA
5e  2 NA NA NA NA

(or the reshape command in R).

On Tue, Sep 1, 2009 at 7:59 PM, Krista Chin0574...@acadiau.ca wrote:
 Hi,

 The lab in which I send my samples return the results in a format that
 is difficult for me to run my analysis.  The lab outputs the results
 where each parameter is its own row and it’s not consistently in the
 same order (and not each sample is tested for the same suite of
 variables).

 e.g.

dataset

 site    parameter  value
 a       e2      3
 a       e1      1
 a       e3      5
 b       e3      1
 b       e1      2
 c       e5      4
 c       e4      5
 c       e2      2
 d       e2      4
 d       e4      3
 e       e1      2

 How would I go about transforming the above table to the one below,
 where each parameter has its own column and there is only 1 row of data
 for each site?

 site    e1      e2      e3      e4      e5
 a       1       3       5       NA      NA
 b       2       NA      3       NA      NA
 c       NA      2       NA      5       4
 d       NA      4       NA      3       NA
 e       2       NA      NA      NA      NA

 I have attempted to write a loop and use the “match” function, but
 it kept getting more and more complicated.  I have a feeling that there
 is simple solution, but I just don’t see it.

 Any insight would be helpful.

 Thanks,
 Krista

        [[alternative HTML version deleted]]


 __
 R-help@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.



__
R-help@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.


[R] Ordering zoo-object by its index

2009-07-09 Thread Sergey Goriatchev
Hello everyone,

Say I have zoo object

x.Date - as.Date(2003-02-01) + c(1, 3, 7, 9, 14) - 1
x - zoo(rnorm(5), x.Date)
y - zoo(rt(5, df=2), x.Date)
z - zoo(rt(5, df=5), x.Date)

Data - merge(x,y,z)

What should I do to make the latest values appear at the top?

Thank you for your help!

Regards,
Sergey

__
R-help@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.


Re: [R] Ordering zoo-object by its index

2009-07-09 Thread Gabor Grothendieck
To display that object in reverse time order try this:

as.data.frame(Data)[nrow(Data):1, ]


On Thu, Jul 9, 2009 at 5:21 AM, Sergey Goriatchevserg...@gmail.com wrote:
 Hello everyone,

 Say I have zoo object

 x.Date - as.Date(2003-02-01) + c(1, 3, 7, 9, 14) - 1
 x - zoo(rnorm(5), x.Date)
 y - zoo(rt(5, df=2), x.Date)
 z - zoo(rt(5, df=5), x.Date)

 Data - merge(x,y,z)

 What should I do to make the latest values appear at the top?

 Thank you for your help!

 Regards,
 Sergey

 __
 R-help@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.


__
R-help@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.


Re: [R] Ordering zoo-object by its index

2009-07-09 Thread Sergey Goriatchev
Hi, Gabor

Thank you!
That is exactly what I did, even before your email. :-)

Regards,
Sergey

On Thu, Jul 9, 2009 at 12:52, Gabor Grothendieckggrothendi...@gmail.com wrote:
 To display that object in reverse time order try this:

 as.data.frame(Data)[nrow(Data):1, ]


 On Thu, Jul 9, 2009 at 5:21 AM, Sergey Goriatchevserg...@gmail.com wrote:
 Hello everyone,

 Say I have zoo object

 x.Date - as.Date(2003-02-01) + c(1, 3, 7, 9, 14) - 1
 x - zoo(rnorm(5), x.Date)
 y - zoo(rt(5, df=2), x.Date)
 z - zoo(rt(5, df=5), x.Date)

 Data - merge(x,y,z)

 What should I do to make the latest values appear at the top?

 Thank you for your help!

 Regards,
 Sergey

 __
 R-help@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.





-- 
I'm not young enough to know everything. /Oscar Wilde
Experience is one thing you can't get for nothing. /Oscar Wilde
When you are finished changing, you're finished. /Benjamin Franklin
Tell me and I forget, teach me and I remember, involve me and I learn.
/Benjamin Franklin
Luck is where preparation meets opportunity. /George Patten

__
R-help@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.


Re: [R] Ordering zoo-object by its index

2009-07-09 Thread Gabor Grothendieck
One additional thought. If the reason you want to do that is
just so that you can see the last few rows more easily then

tail(Data)

will display the last few rows or tail(Data, 10) will display
the last 10 rows.

On Thu, Jul 9, 2009 at 7:36 AM, Sergey Goriatchevserg...@gmail.com wrote:
 Hi, Gabor

 Thank you!
 That is exactly what I did, even before your email. :-)

 Regards,
 Sergey

 On Thu, Jul 9, 2009 at 12:52, Gabor Grothendieckggrothendi...@gmail.com 
 wrote:
 To display that object in reverse time order try this:

 as.data.frame(Data)[nrow(Data):1, ]


 On Thu, Jul 9, 2009 at 5:21 AM, Sergey Goriatchevserg...@gmail.com wrote:
 Hello everyone,

 Say I have zoo object

 x.Date - as.Date(2003-02-01) + c(1, 3, 7, 9, 14) - 1
 x - zoo(rnorm(5), x.Date)
 y - zoo(rt(5, df=2), x.Date)
 z - zoo(rt(5, df=5), x.Date)

 Data - merge(x,y,z)

 What should I do to make the latest values appear at the top?

 Thank you for your help!

 Regards,
 Sergey

 __
 R-help@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.





 --
 I'm not young enough to know everything. /Oscar Wilde
 Experience is one thing you can't get for nothing. /Oscar Wilde
 When you are finished changing, you're finished. /Benjamin Franklin
 Tell me and I forget, teach me and I remember, involve me and I learn.
 /Benjamin Franklin
 Luck is where preparation meets opportunity. /George Patten


__
R-help@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.


  1   2   >