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
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
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 n...@smartmediacorp.com wrote:
That makes perfect sense.
Since I need to build up the results table
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
On Thu, Nov 11, 2010 at 11:33 AM, Noah Silverman
n...@smartmediacorp.com 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 -
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.)
results - data.frame()
n = 10
for(i in 1:n){
+a = LETTERS[i];
+b = i;
+c = 3*i + 2
+
--- On Thu, 11/11/10, William Dunlap wdun...@tibco.com wrote:
From: William Dunlap wdun...@tibco.com
Subject: Re: [R] Populating then sorting a matrix and/or data.frame
To: Peter Langfelder peter.langfel...@gmail.com, r-help@r-project.org
Received: Thursday, November 11, 2010, 4:19 PM
On Thu, Nov 11, 2010 at 1:19 PM, William Dunlap wdun...@tibco.com 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
You are right, I mistyped it.
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
-Original 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
On Thu, Nov 11, 2010 at 1:19 PM, William Dunlap wdun...@tibco.com 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.
Your errors look exactly like mine.
Changing the option flag does allow me to create the data.frame without
any errors. A quick look confirms that all the values are there and
correct.
However, R has coerced all of my numeric values to strings.
Using your sample code also turns all the
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
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
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
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
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 the data:
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 converted all
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
18 matches
Mail list logo