I have a CSV file, with some char fiels and numeric fields and some NaN's located in the file. I want to read the numeric fields as numeric and character fields as characters.
For example my CSV file monthly.csv
is presently like this
Datum,Index,D12,E12,b/m,tbl,AAA
187101,4.44,0.2600,0.4000,NaN,NaN,NaN
187102,4.50,0.2600,0.4000,NaN,NaN,NaN
...
...
...
I am reading this with the following code
monthly <- read.csv2("monthly.csv", sep=',', header = T, na.strings = "NaN", stringsAsFactors=F)
After reading when I view the contents of monthly
variable, I still see the type as
> str(monthly)
'data.frame': 1620 obs. of 7 variables:
$ Datum : int 187101 187102 187103 187104 187105 187106 187107 187108 187109 187110 ...
$ Index : chr "4.44" "4.50" "4.61" "4.74" ...
$ D12 : chr "0.2600" "0.2600" "0.2600" "0.2600" ...
$ E12 : chr "0.4000" "0.4000" "0.4000" "0.4000" ...
$ b.m : chr NA NA NA NA ...
$ tbl : chr NA NA NA NA ...
$ AAA : chr NA NA NA NA ...
Basically only the first field is getting converted to an int
and the rest all are still chr
. How do make the others too as int