[R] Adding columns to lower level of list

Tim Clark mudiver1200 at yahoo.com
Sun Nov 22 05:39:35 CET 2009


Dear List,


I have very little experience with lists and am having some very basic problems.  I don't know how to add columns to the lower levels of a list, or how to take something from the upper level and add it as a column to the lower level.  I am analyzing animal movement data in the package Adehabitat.  I have a list of animal movements called "cut.ltr" (class ltraj) that have been divided into a series of "burst" - i.e. movements with no gaps in time over a given threashold.  I would like to 

1.  Add the speed to each item in the list, and also the burst.  I can calculate speed as:

    sp<-lapply(cut.ltr,function(l){l$dist/l$dt})  

This creates a list of the correct size.  But I don't know how to add this to my original list.  I.e. add a column to the lower levels of the list called "speed".

2.  Add the burst to each lower level of the list.  It is in the upper level, but I don't know how to access it.
I have tried attribute(), attr(), cut.ltr$"burst", and several other creative guesses.

The first five items in the upper level are below - cut.ltr[1:5], along with head(cut.ltr[[1]]).  I would like my final result to have two more columns in cut.ltr[[1]].  One with speed, and the second with burst.

Thanks in advance for your help.

Tim





> cut.ltr[1:5]

*********** List of class ltraj ***********

Type of the traject: Type II (time recorded)
Irregular traject. Variable time lag between two locs

Characteristics of the bursts:
       id     burst nb.reloc NAs          date.begin            date.end
1 Abigail Abigail.1       47   0 2003-05-31 13:29:59 2003-06-01 00:59:56
2 Abigail Abigail.2      288   0 2003-06-18 17:28:11 2003-06-21 17:14:59
3 Abigail Abigail.3       10   0 2003-08-03 23:33:00 2003-08-04 01:43:58
4 Abigail Abigail.4       43   0 2003-08-04 08:15:25 2003-08-04 18:59:58
5 Abigail Abigail.5       78   0 2003-08-05 00:44:19 2003-08-05 20:15:00

> head(cut.ltr[[1]])
         x       y                date         dx       dy     dist  dt       R2n abs.angle   rel.angle
1 809189.8 2189722 2003-05-31 13:29:59   81.87136 315.3389 325.7937 901       0.0  1.316775          NA
2 809271.6 2190037 2003-05-31 13:45:00   13.00097 258.7351 259.0616 901  106141.5  1.520590  0.20381526
3 809284.6 2190296 2003-05-31 14:00:01  250.52656 669.2065 714.5634 898  338561.8  1.212584 -0.30800666
4 809535.2 2190965 2003-05-31 14:14:59 -171.14372 791.1522 809.4516 902 1665046.9  1.783836  0.57125215
5 809364.0 2191756 2003-05-31 14:30:01  302.26979 707.0157 768.9202 900 4169281.4  1.166785 -0.61705039
6 809666.3 2192463 2003-05-31 14:45:01  284.40962 725.2169 778.9919 900 7742615.6  1.197057  0.03027109
> 



Tim Clark
Department of Zoology 
University of Hawaii




More information about the R-help mailing list