0

I am totally new in R and doing an assignment for my studies. While coding I found an error stating "non-numeric argument to mathematical function". I Know the header is causing it, as it is the only non-numeric character in the database. But I don't know how to fix it.

I tried to calculate excluding the header, but couldn't do it.

DF = read.csv("Nominal Broad Dollar Index Modified.csv", header = TRUE)
head(DF)

This is the head of my data frame, & I'm not sure where the x1 column came and whether it is causing the error.

enter image description here

Index = DF$Index
Index0 = Index[DF$Y < 2018]
R0 = diff(log(Index0))

Error in log(Index0) : non-numeric argument to mathematical function

there are no results, I'm just getting errors.

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
  • 1
    Firstly, please do not include pictures of data in your question, add the data using `dput`. Check [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Then, you do not have a column named `Index` in your data set so `DF$Index` would return NULL. – LyzandeR Jun 21 '19 at 09:09
  • Welcome to stackoverflow! Column `X.1` will be the result of a dispensable separator at the end of each line in your csv file (but that and also the column names won't cause the error - as already stated by @LyzandeR, the problem is how you are trying to access the data). – ismirsehregal Jun 21 '19 at 09:14
  • Thanks a lot, guys. My problem is solved. :) – Ittisaf Tamim Jun 21 '19 at 09:29
  • As a general rule, I would also recommend using `read_csv` (or something like it) from the tidyverse package `readr` – p0bs Jun 21 '19 at 09:44

0 Answers0