As usually, I am importing a .csv file from Excel. Since I will be performing some econometric regressions, I m not importing just the values, but also some columns with labels.
df <- read.csv("peasantsworkalot.csv", header=TRUE)
where the df looks like the following
country <- c("AT", "AT", "AT", "AT")
code <- c("AT1", "AT1", "AT2", "AT2")
c <- c("Village1", "Village1", "Village2", "Village2")
d <- c("Year1", "Year1", "Year2", "Year2")
e <- c(65322.09, 62322.01, 84561.06, 86000.02)
df <- cbind(country,code,c,d,e)
df
[1,] "AT" "AT1" "Village1" "Year1" "65322.09"
[2,] "AT" "AT1" "Village1" "Year1" "62322.01"
[3,] "AT" "AT2" "Village2" "Year2" "84561.06"
[4,] "AT" "AT2" "Village2" "Year2" "86000.02"
Whenever I try to make any kind of operation with the values in the e column, I got the following message:
[1] NA
Warning message:
In Ops.factor( ):
+ not meaningful for factors
I suppose that, for somewhat reason it reads the values as non numeric. Therefore I tried
as.numeric(df)
or
as.numeric(df[,5])
The first does not work and gives
Error: (list) object cannot be coerced to type 'double'
The second works but it changes the values. For instance 65322.09 becomes 259 , I don't know for whatever reason. First time this happens and not for any .csv files. Some just work fine.