Hi all, I'm very novice in data.table management, and I have the following 
doubt about this data: > DT <- data.table(obs=1:7, id=c(1,1,1,4,4,4,4), 
time=c(3,4,7,5,8,10,15))> DT   obs id time1:   1  1    32:   2  1    43:   3  1 
   74:   4  4    55:   5  4    86:   6  4   107:   7  4   15 In general, I know 
that I can select respectively the first and the last observation within "id" 
group with:   First observation: DT[!duplicated(id)] Last observation: 
DT[!duplicated(id, fromLast=T)]  But, how can I add a new column, called 
"value", which contains all zeros except:1) The first observation within each 
"id" group, which is equal to 22) The last observation within each "id" group, 
which is equal to 1 ?    obs id time value1:   1  1    3     22:   2  1    4    
 03:   3  1    7     14:   4  4    5     25:   5  4    8     06:   6  4   10    
 07:   7  4   15     1 I've tried with conditionslas, ifelse, etc, but I get an 
error message. Please, can you help me? Thanks in advance!!                     
                            
_______________________________________________
datatable-help mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help

Reply via email to