[R] Odp: better way to trick data frame structure?

Petr PIKAL petr.pikal at precheza.cz
Wed May 5 08:02:27 CEST 2010


Hi

r-help-bounces at r-project.org 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.
> 
> ______________________________________________
> R-help at r-project.org 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.



More information about the R-help mailing list