Ah, I finally figured it out: I had asked
> In both of those cases, why is the [] needed?
It's because when on the left hand side of an assignment, the bracket
operator attempts to preserve the class and dimension of the object it's
subsetting. (Or at least, that's true when the object is a
Wow, those are much more elegant. Thanks!
Peter suggests:
df[] <- lapply(df, factor, levels=allLevels, labels=seq_along(allLevels))
Henrique suggests:
df[] <- as.numeric(unlist(df))
In both of those cases, why is the [] needed? When I evaluate df vs. df[],
they both look the same, but app
Try this also:
df[] <- as.numeric(unlist(df))
df
On Thu, Apr 1, 2010 at 2:53 AM, Jeff Brown wrote:
>
> Sorry for spamming. I swear I had worked on that problem a long time before
> posting.
>
> But I just figured it out: I have to change the values, which are
> represented as integers, not stri
On Thu, Apr 1, 2010 at 3:05 AM, Peter Dalgaard wrote:
> Jeff Brown wrote:
>> Sorry for spamming. I swear I had worked on that problem a long time before
>> posting.
>>
>> But I just figured it out: I have to change the values, which are
>> represented as integers, not strings. So the following c
Jeff Brown wrote:
> Sorry for spamming. I swear I had worked on that problem a long time before
> posting.
>
> But I just figured it out: I have to change the values, which are
> represented as integers, not strings. So the following code will do it:
>
> df <- data.frame (
> a = factor(
Sorry for spamming. I swear I had worked on that problem a long time before
posting.
But I just figured it out: I have to change the values, which are
represented as integers, not strings. So the following code will do it:
df <- data.frame (
a = factor( c( "bob", "alice", "bob" ) ),
Hi,
I've got a data frame with multiple factor columns, but they should share
the same set of labels, such as this tiny example:
df <- data.frame (
a = factor( c( "bob", "alice", "bob" ) ),
b = factor( c( "kenny", "alice", "alice" ) )
);
In my data, though, the strings are enorm
7 matches
Mail list logo