@Michael, in the last expression, you probably forgot a J: frame[J(unique(id)), mult = "last"]
On Tue, Apr 23, 2013 at 7:41 PM, Michael Nelson < [email protected]> wrote: > From the help for data.table::last > > If x is a data.table, the last row as a one row data.table. Otherwise, > whatever xts::last returns. > > > calling lapply(.SD, last) will call last on each column in .SD. Columns > within a data.table aren't data.tables thus `xts::last` is called. xts is > on the suggests list for data.table, > > you could use > > install.packages('data.table, dependencies = 'Suggests') > > or manually installed xts. > > OR > > frame[, last(.SD), by = id] > > would work without needing xts > > as would > > frame[, .SD[.N], by = id] > > or without having to construct .SD (which is time consuming) > > frame[frame[, .I[.N],by = id]$V1] > > or > > setkey(frame, id) > > frame[unique(id), mult = 'last'] > > ________________________________________ > From: [email protected] [ > [email protected]] on behalf of Sam > Steingold [[email protected]] > Sent: Wednesday, 24 April 2013 7:57 AM > To: [email protected] > Subject: [datatable-help] there is no package called ‘xts’ > > Hi, > I got this: > > > dt <- frame[, lapply(.SD, last) ,by=id] > Finding groups (bysameorder=TRUE) ... done in 0.126secs. bysameorder=TRUE > and o__ is length 0 > Optimized j from 'lapply(.SD, last)' to 'list(last(country), > last(language), last(browser), last(platform), last(uatype), > last(behavior))' > Starting dogroups ... Error in loadNamespace(name) : there is no package > called ‘xts’ > Calls: [ -> [.data.table -> last -> :: -> getExportedValue -> asNamespace > -> getNamespace -> tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous> > > > > the help for last does mention xts, but I don't have it installed. > do I need to? > > -- > Sam Steingold (http://sds.podval.org/) on Ubuntu 12.10 (quantal) X > 11.0.11300000 > http://www.childpsy.net/ http://ffii.org http://think-israel.org > http://mideasttruth.com http://memri.org http://camera.org > Ernqvat guvf ivbyngrf QZPN. > _______________________________________________ > datatable-help mailing list > [email protected] > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help > _______________________________________________ > datatable-help mailing list > [email protected] > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help >
_______________________________________________ datatable-help mailing list [email protected] https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
