better way to trick data frame structure?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

better way to trick data frame structure?

Seth
Hi,

I have a data frame where 1 variable is a factor with only 1 level.  I need the data frame structure to reflect that there are 2 levels for this factor, even though this is not the case.  I am currently adding extra 'fake' rows to the data frame to ensure that 2 levels are present, but this is slowing processing time in a loop quite a bit. Can I manually specify that this factor variable has two levels (even though this is lying to R)?  Thanks,Seth
Reply | Threaded
Open this post in threaded view
|

Odp: better way to trick data frame structure?

PIKAL Petr
Hi

[hidden email] napsal dne 05.05.2010 07:49:25:

>
> Hi,
>
> I have a data frame where 1 variable is a factor with only 1 level.  I
need
> the data frame structure to reflect that there are 2 levels for this
factor,
> even though this is not the case.  I am currently adding extra 'fake'
rows
> to the data frame to ensure that 2 levels are present, but this is
slowing
> processing time in a loop quite a bit. Can I manually specify that this
> factor variable has two levels (even though this is lying to R)?

Not at all lying. That is why hated factors are useful. Lust add all
desired levels.

> ff<-factor("M")
> ff
[1] M
Levels: M
> levels(ff)<-c("M","F")
> ff
[1] M
Levels: M F

Regards
Petr

> Thanks,Seth
> --
> View this message in context:
http://r.789695.n4.nabble.com/better-way-to-
> trick-data-frame-structure-tp2130470p2130470.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Odp: better way to trick data frame structure?

Seth
Thanks, works beautifully and saved hours of run time. -seth
Reply | Threaded
Open this post in threaded view
|

Re: Odp: better way to trick data frame structure?

Jim Lemon
In reply to this post by PIKAL Petr
On 05/05/2010 04:02 PM, Petr PIKAL wrote:
>...
> Not at all lying. That is why hated factors are useful. Lust add all
> desired levels.

Hey, isn't this a family mailing list?

Jim

______________________________________________
[hidden email] 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.