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
>>
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
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
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
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
>>
>>
>>
>>
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.
_
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@
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
--- 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
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
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
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
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
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
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
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
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
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
18 matches
Mail list logo