Quantcast

converting character to numeric

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

converting character to numeric

Alina Sheyman-3
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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: converting character to numeric

Denis Kazakiewicz
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]]
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: converting character to numeric

Steven Kennedy-2
In reply to this post by Alina Sheyman-3
You need:
mydata$apples<-as.numeric(mydata$apples)


On Wed, Jun 22, 2011 at 6:38 AM, Alina Sheyman <[hidden email]> 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]]
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: converting character to numeric

Sarah Goslee
In reply to this post by Alina Sheyman-3
Hi Alina,

On Tue, Jun 21, 2011 at 4:38 PM, Alina Sheyman <[hidden email]> 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"
> format

How 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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: converting character to numeric

Bill.Venables
In reply to this post by Steven Kennedy-2
..or something like that.  Without more details it is hard to know just what is going on.

Firstly in R the object is a 'data frame' (or object of class "data.frame" to be formal).  There is no standard object in R called a 'database'.  

If you read in your data using read.csv, then mydata is going to be a data frame.  Character columns in the original .csv file will be (most likely) factors in the R object.  (This varies with how you import it, though.)  This means you will need to convert them to character before you convert them to numeric.  If they really are character, this initial conversion will not do anything (good or bad).

If you want to operate on the individual columns of the data frame, then I would recommend you do it using something like:

mydata <- within(mydata, {
        apples <- as.numeric(as.character(apples))
        oranges <- as.numeric(as.character(oranges))
        .......
})

Bill Venables.

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Steven Kennedy
Sent: Wednesday, 22 June 2011 6:52 AM
To: Alina Sheyman
Cc: [hidden email]
Subject: Re: [R] converting character to numeric

You need:
mydata$apples<-as.numeric(mydata$apples)


On Wed, Jun 22, 2011 at 6:38 AM, Alina Sheyman <[hidden email]> 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]]
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: converting character to numeric

Denis Kazakiewicz
IMHO: 'as.numeric(as.character'   is very reasonable suggestion
On 22.06.2011 01:16, [hidden email] wrote:

> ..or something like that.  Without more details it is hard to know just what is going on.
>
> Firstly in R the object is a 'data frame' (or object of class "data.frame" to be formal).  There is no standard object in R called a 'database'.
>
> If you read in your data using read.csv, then mydata is going to be a data frame.  Character columns in the original .csv file will be (most likely) factors in the R object.  (This varies with how you import it, though.)  This means you will need to convert them to character before you convert them to numeric.  If they really are character, this initial conversion will not do anything (good or bad).
>
> If you want to operate on the individual columns of the data frame, then I would recommend you do it using something like:
>
> mydata<- within(mydata, {
> apples<- as.numeric(as.character(apples))
> oranges<- as.numeric(as.character(oranges))
> .......
> })
>
> Bill Venables.
>
> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On Behalf Of Steven Kennedy
> Sent: Wednesday, 22 June 2011 6:52 AM
> To: Alina Sheyman
> Cc: [hidden email]
> Subject: Re: [R] converting character to numeric
>
> You need:
> mydata$apples<-as.numeric(mydata$apples)
>
>
> On Wed, Jun 22, 2011 at 6:38 AM, Alina Sheyman<[hidden email]>  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]]
>>
>> ______________________________________________
>> [hidden email] 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.
>>
> ______________________________________________
> [hidden email] 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.
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: converting character to numeric

Don McKenzie-2
In reply to this post by Bill.Venables
I have to chime in here with a slight revision to read.csv(), for  
those of us like me who have whined over time about "stringsAsFactors".
(tested on my machine macOSX 10.6)

readFF.csv <-
function (file, header = TRUE, sep = ",", quote = "\"", dec = ".",
     fill = TRUE, comment.char = "", ...)
read.table(file = file, header = header, sep = sep, quote = quote,
     dec = dec, fill = fill, stringsAsFactors=F,comment.char =  
comment.char, ...)


On 21-Jun-11, at 3:16 PM, <[hidden email]> wrote:

> ..or something like that.  Without more details it is hard to know  
> just what is going on.
>
> Firstly in R the object is a 'data frame' (or object of class  
> "data.frame" to be formal).  There is no standard object in R  
> called a 'database'.
>
> If you read in your data using read.csv, then mydata is going to be  
> a data frame.  Character columns in the original .csv file will be  
> (most likely) factors in the R object.  (This varies with how you  
> import it, though.)  This means you will need to convert them to  
> character before you convert them to numeric.  If they really are  
> character, this initial conversion will not do anything (good or bad).
>
> If you want to operate on the individual columns of the data frame,  
> then I would recommend you do it using something like:
>
> mydata <- within(mydata, {
> apples <- as.numeric(as.character(apples))
> oranges <- as.numeric(as.character(oranges))
> .......
> })
>
> Bill Venables.
>
> -----Original Message-----
> From: [hidden email] [mailto:r-help-bounces@r-
> project.org] On Behalf Of Steven Kennedy
> Sent: Wednesday, 22 June 2011 6:52 AM
> To: Alina Sheyman
> Cc: [hidden email]
> Subject: Re: [R] converting character to numeric
>
> You need:
> mydata$apples<-as.numeric(mydata$apples)
>
>
> On Wed, Jun 22, 2011 at 6:38 AM, Alina Sheyman <[hidden email]>  
> 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]]
>>
>> ______________________________________________
>> [hidden email] 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.
>>
>
> ______________________________________________
> [hidden email] 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.
>
> ______________________________________________
> [hidden email] 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.

Science is organized skepticism in the reliability of expert opinion
     -- Richard Feynman




Don McKenzie, Research Ecologist
Pacific WIldland Fire Sciences Lab
US Forest Service

Affiliate Professor
School of Forest Resources, College of the Environment
CSES Climate Impacts Group
University of Washington

phone: 206-732-7824
[hidden email]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: converting character to numeric

Bill.Venables
The point I would make is that for safety it's much better to use FALSE rather than F.  FALSE is a reserved word in R, F is a pre-set variable, but can easily be changed at any time by the user.

Secondly, doesn't this do the same as yours:

readFF.csv <- function(..., stringsAsFactors = FALSE)
        read.csv(..., stringsAsFactors = stringsAsFactors)

?  (Warning: untested code...)

Personally, I much prefer stringsAsFactors = TRUE, but then that's the way I was brought up...

Bill Venables.

-----Original Message-----
From: Don McKenzie [mailto:[hidden email]]
Sent: Wednesday, 22 June 2011 8:40 AM
To: Venables, Bill (CMIS, Dutton Park)
Cc: [hidden email]; [hidden email]; [hidden email]
Subject: Re: [R] converting character to numeric

I have to chime in here with a slight revision to read.csv(), for  
those of us like me who have whined over time about "stringsAsFactors".
(tested on my machine macOSX 10.6)

readFF.csv <-
function (file, header = TRUE, sep = ",", quote = "\"", dec = ".",
     fill = TRUE, comment.char = "", ...)
read.table(file = file, header = header, sep = sep, quote = quote,
     dec = dec, fill = fill, stringsAsFactors=F,comment.char =  
comment.char, ...)


On 21-Jun-11, at 3:16 PM, <[hidden email]> wrote:

> ..or something like that.  Without more details it is hard to know  
> just what is going on.
>
> Firstly in R the object is a 'data frame' (or object of class  
> "data.frame" to be formal).  There is no standard object in R  
> called a 'database'.
>
> If you read in your data using read.csv, then mydata is going to be  
> a data frame.  Character columns in the original .csv file will be  
> (most likely) factors in the R object.  (This varies with how you  
> import it, though.)  This means you will need to convert them to  
> character before you convert them to numeric.  If they really are  
> character, this initial conversion will not do anything (good or bad).
>
> If you want to operate on the individual columns of the data frame,  
> then I would recommend you do it using something like:
>
> mydata <- within(mydata, {
> apples <- as.numeric(as.character(apples))
> oranges <- as.numeric(as.character(oranges))
> .......
> })
>
> Bill Venables.
>
> -----Original Message-----
> From: [hidden email] [mailto:r-help-bounces@r-
> project.org] On Behalf Of Steven Kennedy
> Sent: Wednesday, 22 June 2011 6:52 AM
> To: Alina Sheyman
> Cc: [hidden email]
> Subject: Re: [R] converting character to numeric
>
> You need:
> mydata$apples<-as.numeric(mydata$apples)
>
>
> On Wed, Jun 22, 2011 at 6:38 AM, Alina Sheyman <[hidden email]>  
> 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]]
>>
>> ______________________________________________
>> [hidden email] 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.
>>
>
> ______________________________________________
> [hidden email] 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.
>
> ______________________________________________
> [hidden email] 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.

Science is organized skepticism in the reliability of expert opinion
     -- Richard Feynman




Don McKenzie, Research Ecologist
Pacific WIldland Fire Sciences Lab
US Forest Service

Affiliate Professor
School of Forest Resources, College of the Environment
CSES Climate Impacts Group
University of Washington

phone: 206-732-7824
[hidden email]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: converting character to numeric

Don McKenzie-2
Bill is right on both points.  My longer clumsier code is for  
chickens who are afraid to change any more than they have to.

Don McKenzie

On 21-Jun-11, at 4:36 PM, <[hidden email]> wrote:

> The point I would make is that for safety it's much better to use  
> FALSE rather than F.  FALSE is a reserved word in R, F is a pre-set  
> variable, but can easily be changed at any time by the user.
>
> Secondly, doesn't this do the same as yours:
>
> readFF.csv <- function(..., stringsAsFactors = FALSE)
> read.csv(..., stringsAsFactors = stringsAsFactors)
>
> ?  (Warning: untested code...)
>
> Personally, I much prefer stringsAsFactors = TRUE, but then that's  
> the way I was brought up...
>
> Bill Venables.
>
> -----Original Message-----
> From: Don McKenzie [mailto:[hidden email]]
> Sent: Wednesday, 22 June 2011 8:40 AM
> To: Venables, Bill (CMIS, Dutton Park)
> Cc: [hidden email]; [hidden email]; r-help@r-
> project.org
> Subject: Re: [R] converting character to numeric
>
> I have to chime in here with a slight revision to read.csv(), for
> those of us like me who have whined over time about  
> "stringsAsFactors".
> (tested on my machine macOSX 10.6)
>
> readFF.csv <-
> function (file, header = TRUE, sep = ",", quote = "\"", dec = ".",
>      fill = TRUE, comment.char = "", ...)
> read.table(file = file, header = header, sep = sep, quote = quote,
>      dec = dec, fill = fill, stringsAsFactors=F,comment.char =
> comment.char, ...)
>
>
> On 21-Jun-11, at 3:16 PM, <[hidden email]> wrote:
>
>> ..or something like that.  Without more details it is hard to know
>> just what is going on.
>>
>> Firstly in R the object is a 'data frame' (or object of class
>> "data.frame" to be formal).  There is no standard object in R
>> called a 'database'.
>>
>> If you read in your data using read.csv, then mydata is going to be
>> a data frame.  Character columns in the original .csv file will be
>> (most likely) factors in the R object.  (This varies with how you
>> import it, though.)  This means you will need to convert them to
>> character before you convert them to numeric.  If they really are
>> character, this initial conversion will not do anything (good or  
>> bad).
>>
>> If you want to operate on the individual columns of the data frame,
>> then I would recommend you do it using something like:
>>
>> mydata <- within(mydata, {
>> apples <- as.numeric(as.character(apples))
>> oranges <- as.numeric(as.character(oranges))
>> .......
>> })
>>
>> Bill Venables.
>>
>> -----Original Message-----
>> From: [hidden email] [mailto:r-help-bounces@r-
>> project.org] On Behalf Of Steven Kennedy
>> Sent: Wednesday, 22 June 2011 6:52 AM
>> To: Alina Sheyman
>> Cc: [hidden email]
>> Subject: Re: [R] converting character to numeric
>>
>> You need:
>> mydata$apples<-as.numeric(mydata$apples)
>>
>>
>> On Wed, Jun 22, 2011 at 6:38 AM, Alina Sheyman <[hidden email]>
>> 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]]
>>>
>>> ______________________________________________
>>> [hidden email] 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.
>>>
>>
>> ______________________________________________
>> [hidden email] 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.
>>
>> ______________________________________________
>> [hidden email] 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.
>
> Science is organized skepticism in the reliability of expert opinion
>      -- Richard Feynman
>
>
>
>
> Don McKenzie, Research Ecologist
> Pacific WIldland Fire Sciences Lab
> US Forest Service
>
> Affiliate Professor
> School of Forest Resources, College of the Environment
> CSES Climate Impacts Group
> University of Washington
>
> phone: 206-732-7824
> [hidden email]
>
>
>
>

Science is organized skepticism in the reliability of expert opinion
     -- Richard Feynman




Don McKenzie, Research Ecologist
Pacific WIldland Fire Sciences Lab
US Forest Service

Affiliate Professor
School of Forest Resources, College of the Environment
CSES Climate Impacts Group
University of Washington

phone: 206-732-7824
[hidden email]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Italic fontfaces on specific labels.

Kenneth Roy Cabrera Torres
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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Italic fontfaces on specific labels.

Bert Gunter
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
<[hidden email]> 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
>
> ______________________________________________
> [hidden email] 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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: [SOLVED] Italic fontfaces on specific labels.

Kenneth Roy Cabrera Torres
Thank you for your help...
It works very well!

El mar, 21-06-2011 a las 20:03 -0700, Bert Gunter escribió:
> ?strip.default

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: converting character to numeric

Jonathan Colburn
This post has NOT been accepted by the mailing list yet.
In reply to this post by Alina Sheyman-3
Concerning the original question about the structure of R:

It looks like a data frame object with the name mydata was created in R from the .csv file.  Then, the mydata object was created a second time, overwriting the first mydata with a single column vector from the original data frame.  At that point, mydata$apples no longer exists.   Creating an object such as mydata2 from mydata$apples would therefore be an empty object - if this was indeed the workflow...  Using rm(list = ls()) is great for creating a clean workspace, and rm(mydata) will do the trick if there are other objects needing to be retained.

Jon

Alina Sheyman-3 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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: converting character to numeric

Geordie Kev
This post has NOT been accepted by the mailing list yet.
Something similar has happened to me frequently.

Following NonMEM runs, when bringing the output tables into R using

d<-read.table("tablename",skip=1,header=T,fill=T) option,

I often find columns revert to scientific format, and come out as factors.  These can all be converted simultaneously into numeric using the following:

d<-read.table("tablename",skip=1,header=T,fill=T,stringsAsFactors = FALSE)
ncol<-ncol(d)
d[, c(1:ncol)] <- sapply(d[, c(1:ncol(d))], as.numeric)

str(d) can be used to confirm the correct class of columns.  I'm sure there is a more elegant way, but this works for me....
Loading...