Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in Math.data.frame.....non-numeric variable in data frame:

Tags:

r

I am reading a csv file into R and trying to do take the log of the data. The csv file has columns of data with the first row having text headers and the rest numeric data.

data<-read.csv("rawdata.csv",header=T)
trans<-log(csv2)

I get the following error when I do this:

Error in Math.data.frame(list(Revenue = c(18766L, 20197L, 20777L, 23410L, : non-numeric variable in data frame: Costs

Output of str should have been inserted in Q-body:

data.frame': 167 obs. of 3 variables: 
 $ X: int 18766 20197 20777 23410 23434 22100 22337 21511 22683 23151 ... 
 $ Y: Factor w/ 163 levels "1,452.70","1,469.00",..: 22 9 55 109 158 82 131 112 119 137 ...
 $ Z: num 564 608 636 790 843 ...

How do I correct this?

like image 602
J M Avatar asked Oct 29 '25 10:10

J M


1 Answers

Tada! Y is a factor - big problem. The commas shouldn't be in there.

Also, your original question has some anomalies: data is the loaded data.frame, yet the transformation is applied to csv2. Did you rename the columns? If so, you've not given a full summary of the steps involved. Anyway, the issue is that you have commas in your second column.

like image 182
Iterator Avatar answered Oct 31 '25 00:10

Iterator



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!