[R] automatic coercion to character

David Winsemius dwinsemius at comcast.net
Wed Feb 2 04:31:58 CET 2011


On Feb 1, 2011, at 9:40 PM, Lorenzo Cattarino wrote:

> Hi R users
>
> I am wondering how I can avoid automatic coercion of my numeric vector
> elements to character

Stop giving character arguments .

>
> init <- c(age='N', R=as.numeric(0.5), S=as.numeric(0.8))

If you want a multi-mode object, use a list.

 > init <- list(age='N', R=as.numeric(0.5), S=as.numeric(0.8))
 > init
$age
[1] "N"

$R
[1] 0.5

$S
[1] 0.8

Vectors can only contain elements of a single mode.

-- 
David.
>
>
>
> I have used as.numeric() but it does not seem to work
>
>
>
> Thank you
>
> Lorenzo
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list