[R] apply --> data.frame

PIKAL Petr petr.pikal at precheza.cz
Fri Aug 31 10:39:08 CEST 2012


Hi

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Sam Steingold
> Sent: Thursday, August 30, 2012 9:17 PM
> To: William Dunlap
> Cc: r-help at r-project.org
> Subject: Re: [R] apply --> data.frame
> 
> > * William Dunlap <jqhaync at gvopb.pbz> [2012-08-30 17:35:08 +0000]:
> >
> > I don't agree with your analysis of what went wrong with your example
> >> a double conversion: from number to string first (by c()) and then
> back.
> I did not make myself quite clear, sorry.
> I should have written something like
> c(1,2,"a") ==> "1" "2" "a" =[as.numeric]=> 1 2 "a"

But vector cannot contain values of different mode (character, numeric). There are other structures capable of this. Converting such vector by as numeric inserts NA whenever it encounters non numeric characters.

> as.numeric(c(1,2,"a") )
[1]  1  2 NA
Warning message:
NAs introduced by coercion 

Regards
Petr

> 
> --
> Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X
> 11.0.11103000 http://www.childpsy.net/ http://openvotingconsortium.org
> http://www.memritv.org http://ffii.org http://truepeace.org
> http://palestinefacts.org Those who can't write, write manuals.
> 
> ______________________________________________
> 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