[R] Extract year from date

2015-03-11 Thread ALBERTO VIEIRA FERREIRA MONTEIRO
I think these dates are from some historical database, as they are labeled "BC". And the days might refer to some Epoch of ancient calendars, maybe the Chinese Calendar whose Epoch was 105 BC (at least if we can trust Wikipedia: https://en.wikipedia.org/wiki/Chinese_calendar ) Alberto Monteiro __

Re: [R] Extract year from date

2015-03-09 Thread MacQueen, Don
You need to solve step 1 (converting to Date class) before you can solve step 2 (getting the year as a number). In the data you are starting with, the first value in the Date column is 41163. You don't say whether that column is numeric or character, so let's try it both ways: > as.Date('41163','

Re: [R] Extract year from date

2015-03-08 Thread Mark Sharp
Make the question reproducible (I used dput after getting the data into a dataframe). You need to provide a date of origin for the as.Date function. Try lubridate package. library(lubridate) wells <- structure(list(ID = structure(c(3L, 3L, 2L, 1L, 3L, 2L, 3L, 1L, 1L, 2L, 3L, 2L, 3L, 1L, 2L, 3L

[R] Extract year from date

2015-03-08 Thread Steve Archambault
Hi all, I am trying in vain to create a new object "Year" in my data frame from existing Date data. I have tried many different approaches, but can't seem to get it to work. Here is an example of some code I tried. date1<- as.Date(wells$Date,"%m/%d/%Y") wells$year<-as.numeric(format(date1, "%Y"))