[R] Math.factor error message
David Winsemius
dwinsemius at comcast.net
Tue Feb 16 22:56:09 CET 2010
On Feb 16, 2010, at 4:40 PM, David Winsemius wrote:
>
> 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.
OOOPs. I did not notice that you had attached the file. It's not a tab
separated file and so both of your columns get read in as one
character variable. (or maybe they are commas as decimal points in
which case see below.) You also did not tell read.table() that you
had a header and furthermore to completely complicate things, you
enclosed the two columns within paired double-quotes.
Get rid of the enclosing quotes and read back in with correct
arguments, perhaps sep="," unless you are in a locale that uses commas
as decimal points, in which case you only need read.csv2(). The
fill=TRUE appears superfluous.
>
>
>> 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
>
> ______________________________________________
> 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
Heritage Laboratories
West Hartford, CT
More information about the R-help
mailing list