[R] scientific notation in a data frame

David Winsemius dwinsemius at comcast.net
Wed Mar 21 01:39:35 CET 2012


On Mar 20, 2012, at 7:52 PM, Laura Rodriguez Murillo wrote:

> Dear list,
> I have a data frame where one of the columns are p values with  
> scientific
> notation mixed with regular numbers with decimals.
>> a=data frame
>> a
>      P     OR   N
> 0.50 0.7500 237
> 0.047 1.1030 237
> 0.124 0.7742 237
> 0.124 0.7742 237
> 0.0080 1.1590 237
> 0.50 0.7500 237
> 4.5e-07 1.2 237
> 5.6e-04 0.9 237
>
> when I try to do
>> pval=a$P/2
>
> R gives me an error saying "In Ops.factor(pval, 2) : / not  
> meaningful for
> factors"

It is a complete mystery to me that people don't believe the error  
messages.  a$P is a factor. Something you did created a factor  
(probably at data entry time), and you didn't realize it. You can  
change it to numeric with:

a$P <-  as.numeric(as.character(a$P))

-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list