Re: [R] difference of two rows

2009-11-26 Thread clion
2007 NA 2 15 20033 3 15 20062 4 15 2008 NA 5 21 20061 6 21 2007 NA On Wed, Nov 25, 2009 at 10:55 AM, clion birt...@hotmail.com wrote: Dear R user, I'd like to calculate the difference of two rows, where ID is the same. eg.: I've got the following dataframe: ID YEAR

[R] difference of two rows

2009-11-25 Thread clion
Dear R user, I'd like to calculate the difference of two rows, where ID is the same. eg.: I've got the following dataframe: ID YEAR 13 2007 15 2003 15 2006 15 2008 21 2006 21 2007 and I'd like to get the difference, like this: ID YEAR diff 13 2007 NA 15 2003 3 15 2006 2 15

Re: [R] re ferring to data of previous rows

2009-10-22 Thread clion
))) On Wed, Oct 21, 2009 at 2:55 AM, clion birt...@hotmail.com wrote: Dear Rlers, in the following dataset I would like to insert a new column that refers to the data of the previous row. My question is whether the probability of a female (Id) changes if she had given birth to a pup in the previous

[R] re ferring to data of previous rows

2009-10-21 Thread clion
0 1 1 2005 1 0 1 2006 1 1 1 2007 0 1 2 2003 0 NA 2 2004 1 0 2 2005 1 1 2 2006 0 1 2 2007 1 0 3 2003 1 NA 3 2004 1 1 3 2005 1 1 3 2006 0 1 3 2007 0 0 any idea how I could program that? thanks a lot, clion -- View

[R] autonumber for grouping variable

2009-02-23 Thread clion
Dear R users, my dataframe looks like this head(dat) Id sex byear age 1 300 m 2003 50 2 300 m 2003 36 3 402f 2003 29 4 402f 2003 21 5 402f 2003 64 6 150 m 2005 43 ... ...(where Id is just the Identification number of Individual, sex (male or female), byear

[R] mean over previous cells

2009-02-20 Thread clion
Dear RUsers, I guess this is an easy question for someone a little familiar with programming...(which I am not)... I've got 2 colummns, one shows just dates(SST_date, Class 'Date' num), the other one shows the SeaSurfaceTemperature (SST, num) at that certain date. SST_dateSST 2008-01-01

Re: [R] mean over previous cells

2009-02-20 Thread clion
well, it kind of works now, I get means from the 61st SST-value on (which is reasonable, so no carful discarding of the first 60 values) but aswell I only get means until the 186st SST-value (although I 've got about 4900 in total). Allt the rest is NA - besides the 60th value is NaN Any idea,

Re: [R] length of object in repeated measures

2009-02-09 Thread clion
. (or is there a better way to get a subset?) thanks. Dimitris Rizopoulos-4 wrote: in this case you can use ave(), e.g., say 'dat' is the name of your data frame, then try this: dat$NoCaps - ave(dat$Id, dat$Id, FUN = length) dat I hope it helps. Best, Dimitris clion wrote: Hi