Re: [R] Replacing NAs in long format

2012-11-04 Thread Christopher Desjardins
721 > #5 2 900 > #6 2 1010 > #7 2 1120 > > > A.K. > > > > > > > - Original Message - > From: William Dunlap > To: arun ; Christopher Desjardins < > cddesjard...@gmail.com> &g

Re: [R] Replacing NAs in long format

2012-11-03 Thread arun
n ; Christopher Desjardins Cc: R help Sent: Saturday, November 3, 2012 9:21 PM Subject: RE: [R] Replacing NAs in long format Or, even simpler, > flag <- with(dat2, ave(schyear<=5 & year==0, idr, FUN=any)) > data.frame(dat2, flag)   idr schyear year  flag 1  1      4  -1  TRUE

Re: [R] Replacing NAs in long format

2012-11-03 Thread William Dunlap
hristopher Desjardins > Cc: R help > Subject: Re: [R] Replacing NAs in long format > > ave() or split<-() can make that easier to write, although it > may take some time to internalize the idiom. E.g., > > > flag <- rep(NA, nrow(dat2)) # add as.integer if you prefer 1,

Re: [R] Replacing NAs in long format

2012-11-03 Thread William Dunlap
ilto:r-help-boun...@r-project.org] On > Behalf > Of arun > Sent: Saturday, November 03, 2012 5:01 PM > To: Christopher Desjardins > Cc: R help > Subject: Re: [R] Replacing NAs in long format > > Hi, > May be this helps: > dat2<-read.table(text=" > i

Re: [R] Replacing NAs in long format

2012-11-03 Thread arun
0 #6   2  10    1    0 #7   2  11    2    0 A.K. - Original Message - From: Christopher Desjardins To: jim holtman Cc: r-help@r-project.org Sent: Saturday, November 3, 2012 7:09 PM Subject: Re: [R] Replacing NAs in long format I have a similar sort of follow up and I bet I could re

Re: [R] Replacing NAs in long format

2012-11-03 Thread Christopher Desjardins
I have a similar sort of follow up and I bet I could reuse some of this code but I'm not sure how. Let's say I want to create a flag that will be equal to 1 if schyear < = 5 and year = 0 for a given idr. For example > dat idr schyear year 1 4 -1 1 50 1

Re: [R] Replacing NAs in long format

2012-11-03 Thread Christopher Desjardins
Hi Jim, Thank you so much. That does exactly what I want. Chris On Sat, Nov 3, 2012 at 1:30 PM, jim holtman wrote: > > x <- read.table(text = "idr schyear year > + 1 80 > + 1 91 > + 1 10 NA > + 2 4 NA > + 2 5 -1 > + 2 60 > + 2 7

Re: [R] Replacing NAs in long format

2012-11-03 Thread jim holtman
> x <- read.table(text = "idr schyear year + 1 80 + 1 91 + 1 10 NA + 2 4 NA + 2 5 -1 + 2 60 + 2 71 + 2 82 + 2 93 + 2 104 + 2 11 NA + 2 126 + 3 4 NA + 3 5 -2 +

Re: [R] Replacing NAs in long format

2012-11-03 Thread Rui Barradas
Hello, Try the following. I've called your data.frames 'dat' and 'dat2' # First your datasets, see ?dput dput(dat) structure(list(idr = c(1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), schyear = c(8L, 9L, 10L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 4L, 5L, 6L, 7

[R] Replacing NAs in long format

2012-11-03 Thread Christopher Desjardins
Hi, I have the following data: > data[1:20,c(1,2,20)] idr schyear year 1 80 1 91 1 10 NA 2 4 NA 2 5 -1 2 60 2 71 2 82 2 93 2 104 2 11 NA 2 126 3 4 NA 3 5 -2 3 6 -1 3