I'm trying to convert data from character to numeric. I've imported data as a csv file, I'm assuming that the import is a database - are all the columns in a database considered "vectors" and that they can be operated on individually Therefore I've tried the following mydata <- as.numeric(mydata$apples) when i then look at mydata again the named column is still in "character" format if i do mydata2 <- as.numeric(mydata$apples) the new object mydata2 is empty. Am i missing something about the structure of R? alina [[alternative HTML version deleted]]
Hi Sorry, can't answer your question However, I had exactly the same problem and just came back to my spreadsheet redactor and changed the format of cells Denis> I'm trying to convert data from character to numeric. > > I've imported data as a csv file, I'm assuming that the import is a > database - are all the columns in a database considered "vectors" and that > they can be operated on individually > Therefore I've tried the following > mydata<- as.numeric(mydata$apples) > > when i then look at mydata again the named column is still in "character" > format > if i do mydata2<- as.numeric(mydata$apples) > the new object mydata2 is empty. > > Am i missing something about the structure of R? > > alina > > [[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.
You need: mydata$apples<-as.numeric(mydata$apples) On Wed, Jun 22, 2011 at 6:38 AM, Alina Sheyman <alinashe at gmail.com> wrote:> I'm trying to convert data from character to numeric. > > ?I've imported data as a csv file, I'm assuming that the import is a > database - are all the columns in ?a database considered "vectors" ?and that > they can be ?operated on individually > Therefore I've tried the following > mydata <- as.numeric(mydata$apples) > > when i then look at mydata again ?the named column is still in "character" > format > ?if i do mydata2 <- as.numeric(mydata$apples) > the new object mydata2 is empty. > > Am i missing something about the structure of R? > > alina > > ? ? ? ?[[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. >
Hi Alina, On Tue, Jun 21, 2011 at 4:38 PM, Alina Sheyman <alinashe at gmail.com> wrote:> I'm trying to convert data from character to numeric. > > ?I've imported data as a csv file, I'm assuming that the import is a > database - are all the columns in ?a database considered "vectors" ?and that > they can be ?operated on individually > Therefore I've tried the following > mydata <- as.numeric(mydata$apples)The term is data frame, not database. You don't tell us how you imported the data - read.table()? read.csv()? Using what options? You are right that each column can be operated on individually. Are you certain that every element in mydata$apples is numeric? If it were, read.table() wouldn't import it as character, but as numeric. What does str(mydata) show?> when i then look at mydata again ?the named column is still in "character" > formatHow did you determine that?> ?if i do mydata2 <- as.numeric(mydata$apples) > the new object mydata2 is empty.This perplexes me; it means that R can't identify ANY of the information in your column as numeric. If some were numeric and some character, you would get a warning and the character values would be replaced with NA.> vec1 <- c("1", "2", "3") > as.numeric(vec1)[1] 1 2 3> vec1 <- c("1", "2", "3", "a") > as.numeric(vec1)[1] 1 2 3 NA Warning message: NAs introduced by coercion Are you certain that "apples" is the correct column name? R is case-sensitive.> Am i missing something about the structure of R? >It's hard to tell. You are certainly missing a lot of the information we need to answer your question. Sarah -- Sarah Goslee http://www.functionaldiversity.org
Use strip = strip.custom(...) in the xyplot call to alter the parameters of the function that produces the strips. In particular, see the par.strip.text argument of ?strip.default. Cheers, Bert On Tue, Jun 21, 2011 at 6:36 PM, Kenneth Roy Cabrera Torres <krcabrer at une.net.co> wrote:> Hi R users: > > I want to have a italic font on the microorganism names, > but not on the other labels. > > How can I do that? > > library(lattice) > t<-rep(seq(0,20,5),2) > logCFU<-c(2,2.5,3,4,4.5,1.5,2,2.5,3,3.4) > microorg<-factor(rep(c("E. coli","L. monocytogenes"),each=5)) > xyplot(logCFU~t|microorg,fontface="italic") > > Thank you for your help. > > Kenneth > > ______________________________________________ > 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. >-- "Men by nature long to get on to the ultimate truths, and will often be impatient with elementary studies or fight shy of them. If it were possible to reach the ultimate truths without the elementary studies usually prefixed to them, these would not be preparatory studies but superfluous diversions." -- Maimonides (1135-1204) Bert Gunter Genentech Nonclinical Biostatistics