Re: [R] as.Date() function

2018-08-21 Thread John Kane via R-help
You loaded "lubridate" so using Erin's approach library(lubridate) st <- c("1961-01","1961-04","1983-02") dat1 <- ymd(paste( st, "01",  sep ="-")) On Monday, August 20, 2018, 1:15:56 a.m. EDT, wrote: Thanks Erin and Jim. You have indeed solved my problem. Philip Quoting Erin Hodg

Re: [R] as.Date() function

2018-08-21 Thread Erin Hodgess
Nice one! On Tue, Aug 21, 2018 at 6:14 PM John Kane wrote: > You loaded "lubridate" so using Erin's approach > > library(lubridate) > st <- c("1961-01","1961-04","1983-02") > dat1 <- ymd(paste( st, "01", sep ="-")) > > > On Monday, August 20, 2018, 1:15:56 a.m. EDT, < > phili...@cpanel1.stormw

Re: [R] as.Date() function

2018-08-19 Thread philipsm
Thanks Erin and Jim. You have indeed solved my problem. Philip Quoting Erin Hodgess : Hi Philip: Here is something to consider: #potential solution: sta <- paste(st,"-01",sep="") st1 <- as.Date(sta, format=("%Y-%m-%d")) print(st1) [1] "1961-01-01" "1961-04-01" "1983-02-01" Hope this hel

Re: [R] as.Date() function

2018-08-19 Thread Jim Lemon
Hi Phillip, Jose has the correct answer. You probably missed this sentence in the "Note" section of the help page: "If the date string does not specify the date completely, the returned answer may be system-specific." In your case, the function throws up its hands and returns NA as you haven't sp

Re: [R] as.Date() function

2018-08-19 Thread José María Mateos
On Sun, Aug 19, 2018 at 05:20:29PM -0400, phili...@cpanel1.stormweb.net wrote: > Why the heck am I getting three NAs instead of three Dates?I have > studied the R documentation for as.Date() and it has not turned on > the light bulb for me. I haven't encountered this problem before, but in my mind

Re: [R] as.Date() function

2018-08-19 Thread Erin Hodgess
Hi Philip: Here is something to consider: > #potential solution: > sta <- paste(st,"-01",sep="") > st1 <- as.Date(sta, format=("%Y-%m-%d")) > print(st1) [1] "1961-01-01" "1961-04-01" "1983-02-01" Hope this helps! Erin Erin Hodgess, PhD mailto: erinm.hodg...@gmail.com On Sun, Aug 19, 2018 at

[R] as.Date() function

2018-08-19 Thread philipsm
I am having trouble with what must be a very simple problem. Here is a reproducible example: library(lubridate) st <- c("1961-01","1961-04","1983-02") print(st) #[1] "1961-01" "1961-04" "1983-02" st1 <- as.Date(st, format=("%Y-%m")) print(st1) #[1] NA NA NA Why the heck am I getting three NAs

Re: [R] as.Date function error

2011-04-17 Thread Achim Zeileis
On Sun, 17 Apr 2011, Wonjae Lee wrote: Hi, I have some problems with as.Date function. After I applied as.Date for my data, "2010" changed to "2020" as below Where am I wrong? You used %y (two-digit year, here: "20" and then expanded to "2020") instead of %Y (four-digit year, here "2010").

Re: [R] as.Date function error

2011-04-17 Thread Dennis Murphy
as.Date(x,"%m/%d/%Y") [1] "2010-11-16" "2010-11-17" "2010-11-18" "2010-11-19" Notice the Y (four digit date). Dennis On Sun, Apr 17, 2011 at 6:34 AM, Wonjae Lee wrote: > Hi, > > I have some problems with as.Date function. > After I applied as.Date for my data, "2010" changed to "2020" as below

[R] as.Date function error

2011-04-17 Thread Wonjae Lee
Hi, I have some problems with as.Date function. After I applied as.Date for my data, "2010" changed to "2020" as below Where am I wrong? Thanks Wonjae > x=c("11/16/2010","11/17/2010","11/18/2010","11/19/2010") > x=as.Date(x,"%m/%d/%y") > x [1] "2020-11-16" "2020-11-17" "2020-11-18" "2020-11-19"