This question already has an answer here:
- as.Date with dates in format m/d/y in R 2 answers
My problem is that the as.Date function does not convert the values in a "date" column of a data frame into Date objects.
I have a data.frame
nmmaps
. Here is a short portion of it.
city date death temp dewpoint pm10 o3 time season
1 chic 1/1/1987 130 31.5 31.500 27.79119 4.025928 1 winter
2 chic 1/2/1987 150 33.0 29.875 NA 4.579652 2 winter
3 chic 1/3/1987 101 33.0 27.375 33.67382 3.400928 3 winter
4 chic 1/4/1987 135 29.0 28.625 40.79119 3.942595 4 winter
5 chic 1/5/1987 126 32.0 28.875 NA 4.400928 5 winter
6 chic 1/6/1987 130 40.0 35.125 41.79119 5.984261 6 winter
I imported the data from an Excel file with the following command:
nmmaps <- read.csv("chicago-nmmaps.csv" , as.is = T)
When I get to the point of converting by as.Date, I enter nmmaps$date <- as.Date(nmmaps$date)
and get a data.frame
shown below.
city date death temp dewpoint pm10 o3 time season
1 chic 0001-01-19 130 31.5 31.500 27.79119 4.025928 1 winter
2 chic 0001-02-19 150 33.0 29.875 NA 4.579652 2 winter
3 chic 0001-03-19 101 33.0 27.375 33.67382 3.400928 3 winter
4 chic 0001-04-19 135 29.0 28.625 40.79119 3.942595 4 winter
5 chic 0001-05-19 126 32.0 28.875 NA 4.400928 5 winter
6 chic 0001-06-19 130 40.0 35.125 41.79119 5.984261 6 winter
Why are the dates shown this way? Also, some dates have a NA
field. I would like the years to shown as 1987, 1988, 1989, etc..