I have a data.table of the format
id | pet   | name  
2011-01-01 | "dog" | "a"  
2011-01-02 | "dog" | "b"  
2011-01-03 | "cat" | "c"  
2011-01-04 | "dog" | "a"  
2011-01-05 | "dog" | "some"   
2011-01-06 | "cat" | "thing"
I want to perform an aggregate that concatenates all the dog names that appear before the cat occurs e.g.,
id | pet   | name   | prior  
2011-01-01 | "dog" | "a"     |  
2011-01-02 | "dog" | "b"     |  
2011-01-03 | "cat" | "c"     |  "a b"  
2011-01-04 | "dog" | "a"     |  
2011-01-05 | "dog" | "some"  |  
2011-01-06 | "cat" | "thing" | "a some"  
				
                        
Try
Or a possible solution with
shift(introduced in the devel version ie. v1.9.5), inspired from @David Arenburg's post. Instructions to install the devel version are here.data