[R] Math.factor error message

David Winsemius dwinsemius at comcast.net
Tue Feb 16 22:40:18 CET 2010


On Feb 16, 2010, at 2:25 PM, Hichem Ben Khedhiri wrote:

> Dear R-helpers,
>
> I am using a vrtest on time series data. My commands are as follows;
>
> read.table("B.txt",sep="\t",fill=TRUE, na.strings = "NA")
>
> require(vrtest)
>
> rm(list=ls(all=TRUE))
>
> datamat <- read.table("B.txt",sep="\t",fill=TRUE, na.strings = "NA")
>
> column <- 1
>
> nob <- nrow(datamat)
>
> y <- log(datamat[2:nob,column])-log(datamat[1:(nob-1),column])
>
> After, the use of last command, I get the following message;
>
> in Math.factor(c(37L, 36L, 42L, 41L, 44L, 38L, 31L, 61L, 66L, 91L,  :
>
>  log not meaningful for factors
>
>
> My data is composed of one column.

It appears that you may need to apply as.numeric(as.character( )) to  
that column after input (See the FAQ if you don't know why you need  
both functions.) You seem to have created a factor in datamat. You can  
prevent factor-formation with stringsAsFactors or colClasses arguments  
to read.table.


> I would appreciate, if any one could provide me with some hints to get
> around the problem.
>
>
>
> Best regards,
>


David Winsemius, MD
Heritage Laboratories
West Hartford, CT



More information about the R-help mailing list