Kurt_Helf at nps.gov
2010-Oct-13 14:49 UTC
[R] strip month and year from MM/DD/YYYY format
Greetings I'm having difficulty witht the strptime function. I can't seem to figure a way to strip month (name) and year and create separate columns from a column with MM/DD/YYYY formatted dates. Can anyone help? Cheers Kurt *************************************************************** Kurt Lewis Helf, Ph.D. Ecologist EEO Counselor National Park Service Cumberland Piedmont Network P.O. Box 8 Mammoth Cave, KY 42259 Ph: 270-758-2163 Lab: 270-758-2151 Fax: 270-758-2609 **************************************************************** Science, in constantly seeking real explanations, reveals the true majesty of our world in all its complexity. -Richard Dawkins The scientific tradition is distinguished from the pre-scientific tradition in having two layers. Like the latter it passes on its theories but it also passes on a critical attitude towards them. The theories are passed on not as dogmas but rather with the challenge to discuss them and improve upon them. -Karl Popper ...consider yourself a guest in the home of other creatures as significant as yourself. -Wayside at Wilderness Threshold in McKittrick Canyon, Guadalupe Mountains National Park, TX Cumberland Piedmont Network (CUPN) Homepage: http://tiny.cc/e7cdx CUPN Forest Pest Monitoring Website: http://bit.ly/9rhUZQ CUPN Cave Cricket Monitoring Website: http://tiny.cc/ntcql CUPN Cave Aquatic Biota Monitoring Website: http://tiny.cc/n2z1o
On Wed, Oct 13, 2010 at 10:49 AM, <Kurt_Helf at nps.gov> wrote:> Greetings > ? ?I'm having difficulty witht the strptime function. ?I can't seem to > figure a way to strip month (name) and year and create separate columns > from a column with MM/DD/YYYY formatted dates. ?Can anyone help?Try month.day.year in chron:> library(chron) > dat <- as.Date(c("6/12/2009", "4/15/2010"), "%m/%d/%Y") > month.day.year(dat)$month [1] 6 4 $day [1] 12 15 $year [1] 2009 2010> # or > as.data.frame(month.day.year(dat))month day year 1 6 12 2009 2 4 15 2010 -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com