Hi R users I am wondering how I can avoid automatic coercion of my numeric vector elements to character init <- c(age='N', R=as.numeric(0.5), S=as.numeric(0.8)) I have used as.numeric() but it does not seem to work Thank you Lorenzo [[alternative HTML version deleted]]
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 characterStop 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
Tena koe Lorenz c() combines the elements to form a vector and all elements of a vector must be of the same type. If you elements of different types you need to use a list. Note, a data.frame is a special type of list. HTH .... Peter Alspach> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Lorenzo Cattarino > Sent: Wednesday, 2 February 2011 3:40 p.m. > To: r-help at r-project.org > Subject: [R] automatic coercion to character > > Hi R users > > > > I am wondering how I can avoid automatic coercion of my numeric vector > elements to character > > > > init <- c(age='N', R=as.numeric(0.5), S=as.numeric(0.8)) > > > > 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.The contents of this e-mail are confidential and may be subject to legal privilege. If you are not the intended recipient you must not use, disseminate, distribute or reproduce all or any part of this e-mail or attachments. If you have received this e-mail in error, please notify the sender and delete all material pertaining to this e-mail. Any opinion or views expressed in this e-mail are those of the individual sender and may not represent those of The New Zealand Institute for Plant and Food Research Limited.