Hi all, 1. How to construct a date from three variables year, month, and day, where all three are integers? 2. I have a dataframe by date and sector. I would like to add-up all entries for all variable with identical date and sector, replacing the original entries, i.e. emulate the STATA command "collapse (sum) var1 var2 var3, by(date sector)". Thank you, Serguei Kaniovski
On Fri, 3 Mar 2006, Serguei Kaniovski wrote:> Hi all, > > 1. How to construct a date from three variables year, month, and day, > where all three are integers??ISOdate (and perhaps use as.Date on the result)> 2. I have a dataframe by date and sector. I would like to add-up all > entries for all variable with identical date and sector, replacing the > original entries, i.e. emulate the STATA command "collapse (sum) var1 > var2 var3, by(date sector)".?by (I am not sure how you replace the original entries, as the result is far shorter. If you mean that you want to replace each of the entries for date/sector by the sum for that date/sector use indexing, but this is much more commonly done for the mean. As ever, an example would have helped clarify your intentions.) -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
The second question: STATA: use auto collapse (sum) price mpg,by( make foreign) R: if you have the same data set named auto in R whatyouwant <- aggregate(auto[,c("mpg","price")],by=auto[,c("make","foreign")],FUN=sum) 2006/3/3, Serguei Kaniovski <kaniovsk at wsr.ac.at>:> Hi all, > > 1. How to construct a date from three variables year, month, and day, > where all three are integers? > > 2. I have a dataframe by date and sector. I would like to add-up all > entries for all variable with identical date and sector, replacing the > original entries, i.e. emulate the STATA command "collapse (sum) var1 > var2 var3, by(date sector)". > > Thank you, > Serguei Kaniovski > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >-- ?????? Deparment of Sociology Fudan University
DF$date <- as.Date(paste(DF$day,DF$month,DF$year), "%d %m %Y") # if 4-figure year aggregate(DF[c(var1, var2, var3)], DF[c(date, sector)], sum, is.na=T) Serguei Kaniovski a ?crit :>Hi all, > >1. How to construct a date from three variables year, month, and day, >where all three are integers? > >2. I have a dataframe by date and sector. I would like to add-up all >entries for all variable with identical date and sector, replacing the >original entries, i.e. emulate the STATA command "collapse (sum) var1 >var2 var3, by(date sector)". > >Thank you, >Serguei Kaniovski > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > > >