[R] R-question

Jim Lemon jim at bitwrit.com.au
Thu Sep 14 02:47:13 CEST 2006


Thorsten Muehge wrote:
> 
> Hello Colleagues,
> I programmed in SAS for 3 years and would like to switch to a not so costly
> software product.
> 
> Hence I started to evaluate R, and my first test look promising.
> 
> However I have some question:
> 
> 1. Is it possible to query R files by SQL internally on data frames (not on
> a database) and how is the syntax (I have the RODBC package installed).
> 
> I would like to extract year, Quarter, week, from a date column in a data
> frame (see attachment). After this I want to attach the column to the
> original data frame.
> 
> How do I do this in R?

Hi Thorsten,

You may just want to convert the dates as follows, adding them to the 
data frame on the fly:

test.df<-data.frame(dates=as.POSIXlt(c("2004-05-13","2005-07-23","2006-09-13")),
  nums=rnorm(3))
test.df$years<-format(test.df$dates,"%Y")
test.df$quarters<-floor((as.numeric(format(test.df$dates,"%m"))-1)/3)+1
test.df$week<-format(test.df$dates,"%U")
test.df

Jim



More information about the R-help mailing list