Re: [R] Populating then sorting a matrix and/or data.frame

2010-11-11 Thread Noah Silverman
David, Great solution. While a bit longer to enter, it lets me explicitly define a type for each column. Thanks!!! -N On 11/11/10 4:02 PM, David Winsemius wrote: > > On Nov 11, 2010, at 6:38 PM, Noah Silverman wrote: > >> That makes perfect sense. All of my numbers are being coerced into >>

Re: [R] Populating then sorting a matrix and/or data.frame

2010-11-11 Thread David Winsemius
On Nov 11, 2010, at 6:38 PM, Noah Silverman wrote: That makes perfect sense. All of my numbers are being coerced into strings by the c() function. Subsequently, my data.frame contains all strings. I can't know the length of the data.frame ahead of time, so can't predefine it like your exampl

Re: [R] Populating then sorting a matrix and/or data.frame

2010-11-11 Thread Peter Langfelder
I see 4 ways to write the code: 1. make the frame very long at the start and use my code - this is practical if you know that your data frame will not be longer than a certain number of rows, be it a million; 2a. use something like result1 = data.frame(a=a, b=b, c=c, d=d) within the loop to cre

Re: [R] Populating then sorting a matrix and/or data.frame

2010-11-11 Thread Noah Silverman
That makes perfect sense. All of my numbers are being coerced into strings by the c() function. Subsequently, my data.frame contains all strings. I can't know the length of the data.frame ahead of time, so can't predefine it like your example. One thought would be to make it arbitrarily long fil

Re: [R] Populating then sorting a matrix and/or data.frame

2010-11-11 Thread Noah Silverman
nal Message- >> From: John Kane [mailto:jrkrid...@yahoo.ca] >> Sent: Thursday, November 11, 2010 1:58 PM >> To: Peter Langfelder; r-help@r-project.org; William Dunlap >> Subject: Re: [R] Populating then sorting a matrix and/or data.frame >> >> >> >>

Re: [R] Populating then sorting a matrix and/or data.frame

2010-11-11 Thread Peter Langfelder
On Thu, Nov 11, 2010 at 1:19 PM, William Dunlap wrote: > Peter, > > Your example doesn't work for me unless I > set options(stringsAsFactors=TRUE) first. Yes, you need to set options(stringsAsFactors=FALSE) (note the FALSE). I do it always so I forgot about that, sorry. _

Re: [R] Populating then sorting a matrix and/or data.frame

2010-11-11 Thread William Dunlap
Subject: Re: [R] Populating then sorting a matrix and/or data.frame > > > > --- On Thu, 11/11/10, William Dunlap wrote: > > > From: William Dunlap > > Subject: Re: [R] Populating then sorting a matrix and/or data.frame > > To: "Peter Langfelder" , > r-help@

Re: [R] Populating then sorting a matrix and/or data.frame

2010-11-11 Thread Peter Langfelder
On Thu, Nov 11, 2010 at 1:19 PM, William Dunlap wrote: > Peter, > > Your example doesn't work for me unless I > set options(stringsAsFactors=TRUE) first. > (If I do set that, then all columns of 'results' > have class "character", which I doubt the user > wants.) You probably mean stringsAsFactor

Re: [R] Populating then sorting a matrix and/or data.frame

2010-11-11 Thread John Kane
--- On Thu, 11/11/10, William Dunlap wrote: > From: William Dunlap > Subject: Re: [R] Populating then sorting a matrix and/or data.frame > To: "Peter Langfelder" , r-help@r-project.org > Received: Thursday, November 11, 2010, 4:19 PM > Peter, > > Your examp

Re: [R] Populating then sorting a matrix and/or data.frame

2010-11-11 Thread William Dunlap
9 10 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 Peter Langfelder > Sent: Thursday, November 11, 2010

Re: [R] Populating then sorting a matrix and/or data.frame

2010-11-11 Thread Peter Langfelder
On Thu, Nov 11, 2010 at 11:33 AM, Noah Silverman wrote: > Still doesn't work. > > When using rbind to build the data.frame, it get a structure mostly full of > NA. > The data is correct, so something about pushing into the data.frame is > breaking. > > Example code: > results <- data.frame() > > f

Re: [R] Populating then sorting a matrix and/or data.frame

2010-11-11 Thread Noah Silverman
Still doesn't work. When using rbind to build the data.frame, it get a structure mostly full of NA. The data is correct, so something about pushing into the data.frame is breaking. Example code: results <- data.frame() for(i in 1:n){ #do all the work #a is a test label. b,c,d are num

Re: [R] Populating then sorting a matrix and/or data.frame

2010-11-11 Thread Michael Bedward
You can use rbind as in your original post, but if you've got a mix of character and numeric data start with a data.frame rather than a matrix. Michael On 11 November 2010 20:30, Noah Silverman wrote: > That makes perfect sense. > > Since I need to build up the results table sequentially as I it

Re: [R] Populating then sorting a matrix and/or data.frame

2010-11-11 Thread Noah Silverman
That makes perfect sense. Since I need to build up the results table sequentially as I iterate through the data, how would you recommend it?? Thanks, -N On 11/11/10 12:03 AM, Michael Bedward wrote: All values in a matrix are the same type, so if you've set up a matrix with a character colum

Re: [R] Populating then sorting a matrix and/or data.frame

2010-11-11 Thread Michael Bedward
All values in a matrix are the same type, so if you've set up a matrix with a character column then your numeric values will also be stored as character. That would explain why they are being converted to factors. It would also explain why your query isn't working. Michael On 11 November 2010 1

Re: [R] Populating then sorting a matrix and/or data.frame

2010-11-10 Thread Noah Silverman
That was a typo. It should have read: results[results$one < 100,] It does still fail. There is ONE column that is text. So my guess is that R is seeing that and assuming that the entire data.frame should be factors. -N On 11/10/10 11:16 PM, Michael Bedward wrote: Hello Noah, If you set t

Re: [R] Populating then sorting a matrix and/or data.frame

2010-11-10 Thread Michael Bedward
Hello Noah, If you set these names... > names(results) <- c("one", "two", "three") this won't work... > results[results$c < 100,] because you don't have a column called "c" (unless that's just a typo in your post). > I tried making it a data.frame with > foo <- data.frame(results) > > But that

[R] Populating then sorting a matrix and/or data.frame

2010-11-10 Thread Noah Silverman
Hi, I have a process in R that produces a lot of output. My plan was to build up a matrix or data.frame "row by row", so that I'll have a nice object with all the resulting data. I started with: results <- matrix(ncol=3) names(results) <- c("one", "two", "three") Then, when looping through