[R-SIG-Finance] extracting a subTable

Carlos J. Gil Bellosta cgb at datanalytics.com
Thu Jan 15 00:24:22 CET 2009


Hello,

Something you can do is first, find the indexes to extract as follows:

indexes.to.extract <- tapply(table.1$Seq, tablle.1$ID, max)

Then, table.2 is just

table.2 <- table.1[ indexes.to.extract, ]

You could do it in just one line. I think this is as efficient as it can
get.

Best regards,

Carlos J. Gil Bellosta
http://www.datanalytics.com


On Wed, 2009-01-14 at 16:30 -0500, Jorge Nieves wrote:
> Hi,
> 
> I have a BIG table with data organized by ID, see example on Table#1
> bellow. I would like to extract a smaller table with the same number of
> columns. The rows should include only the last ROW of each ID. Table# 2
> is an example extracted form table #1. I tried using the SUBSET function
> and plan to loop, but I was wondering if someone out there has a more
> efficient way to accomplish this.
> 
> You recommendations are highly appreciated.
> 
> Jorge
> 	
> 
> 	Table # 1					Table # 2
> 
> 	Seq	ID	X1	X2		Seq	ID	X1
> X2		
> 	1	15	-616	796		12	15	-148
> 878		
> 	2	15	-661	-455		20	20	-515
> 1,802		
> 	3	15	-355	-1,639		27	45	-138
> 179		
> 	4	15	-1,226	-97		34	70	1,348
> 840		
> 	5	15	506	985
> 
> 	6	15	-612	76
> 
> 	7	15	947	122
> 
> 	8	15	-45	1,980
> 
> 	9	15	295	-1,827
> 
> 	10	15	1,490	-743
> 
> 	11	15	115	1,283
> 
> 	12	15	-148	878
> 
> 	13	20	359	1,297
> 
> 	14	20	-185	-430
> 
> 	15	20	481	800
> 
> 	16	20	1,567	874
> 
> 	17	20	2,365	-167
> 
> 	18	20	1,636	1,649
> 
> 	19	20	-2,741	337
> 
> 	20	20	-515	1,802
> 
> 	21	45	90	624
> 
> 	22	45	-221	345
> 
> 	23	45	-2,168	-1,734
> 
> 	24	45	1,056	-1,070
> 
> 	25	45	678	-80
> 
> 	26	45	1,747	-74
> 
> 	27	45	-138	179
> 
> 	28	70	1,152	-3,167
> 
> 	29	70	-802	-337
> 
> 	30	70	-388	263
> 
> 	31	70	812	342
> 
> 	32	70	-576	972
> 
> 	33	70	653	-737
> 
> 	34	70	1,348	840
> 
> 	
> 
> 	
> 
> Jorge Nieves
> Phone 212.782.7083
> Fax 212.642.7644
> 
> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.



More information about the R-SIG-Finance mailing list