Re: [R] Replace missing value within group with non-missing value

2013-04-07 Thread Leask, Graham
nal Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Rui Barradas > Sent: Saturday, April 06, 2013 10:24 AM > To: Leask, Graham > Cc: r-help@r-project.org > Subject: Re: [R] Replace missing value within group with non-m

Re: [R] Replace missing value within group with non-missing value

2013-04-06 Thread William Dunlap
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf > Of Rui Barradas > Sent: Saturday, April 06, 2013 10:24 AM > To: Leask, Graham > Cc: r-help@r-project.org > Subject: Re: [R] Replace missing value within group with non-missing value > >

Re: [R] Replace missing value within group with non-missing value

2013-04-06 Thread Leask, Graham
: [R] Replace missing value within group with non-missing value Hi, dat<- read.csv("test1.csv",sep=",",stringsAsFactors=FALSE) sp <- split(dat, list(dat$dn, dat$obs)) sp1<-sp[lapply(sp,nrow)!=0] #added here names(sp1) <- NULL tmp<- lapply(sp1,function(x){  i

Re: [R] Replace missing value within group with non-missing value

2013-04-06 Thread Rui Barradas
t;, "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47&qu

Re: [R] Replace missing value within group with non-missing value

2013-04-06 Thread arun
6 487 A.K. - Original Message - From: "Leask, Graham" To: Rui Barradas Cc: arun ; "r-help@r-project.org" Sent: Saturday, April 6, 2013 1:44 PM Subject: RE: [R] Replace missing value within group with non-missing value Hi Rui, I have just pasted this direct and reru

Re: [R] Replace missing value within group with non-missing value

2013-04-06 Thread Leask, Graham
call(rbind,tmp) Error in do.call(rbind, tmp) : object 'tmp' not found Any thoughts on what could be causing this anomaly? -Original Message- From: Rui Barradas [mailto:ruipbarra...@sapo.pt] Sent: 06 April 2013 18:24 To: Leask, Graham Cc: arun; r-help@r-project.org Subject: Re: [R

Re: [R] Replace missing value within group with non-missing value

2013-04-06 Thread Rui Barradas
uot;36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50"), class = "data.frame") sp <- split(dat, list(da

Re: [R] Replace missing value within group with non-missing value

2013-04-06 Thread Leask, Graham
1 1 6 487 Best wishes Graham -Original Message- From: David Winsemius [mailto:dwinsem...@comcast.net] Sent: 06 April 2013 17:46 To: David Winsemius Cc: Leask, Graham; r-help@r-project.org Subject: Re: [R] Replace missing value within group with non-missing value On Apr 6, 2013, a

Re: [R] Replace missing value within group with non-missing value

2013-04-06 Thread Leask, Graham
;, "41", "42", "43", "44", "45", "46", "47", "48", "49", "50"), class = "data.frame") > sp <- split(dat, list(dat$dn, dat$obs)) > names(sp) <- NULL > tmp <- lapply

Re: [R] Replace missing value within group with non-missing value

2013-04-06 Thread David Winsemius
; # ... or this: > dat$mth <- na.locf(dat$mth, na.rm=FALSE) If on the other hand you wnated cases to be be handled within individual values of "obs" then you could do this to the categories of obs where there was a value to replace (omitting the last two rows): dat$mth[-(49:50)] <-

Re: [R] Replace missing value within group with non-missing value

2013-04-06 Thread Rainer Schuermann
, "15", > "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", > "27", "28", "29", "30", "31", "32", "

Re: [R] Replace missing value within group with non-missing value

2013-04-06 Thread David Winsemius
39", "40", "41", "42", "43", "44", "45", "46", "47", "48", > "49", "50"), class = "data.frame") > Looks like a job for na.locf in the zoo package: require(zoo) #

Re: [R] Replace missing value within group with non-missing value

2013-04-06 Thread Leask, Graham
uot;31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "

Re: [R] Replace missing value within group with non-missing value

2013-04-06 Thread Leask, Graham
] Replace missing value within group with non-missing value Hello, Can't you post a data example? If your dataset is named 'dat' use dput(head(dat, 50)) # paste the output of this in a post Rui Barradas Em 06-04-2013 15:34, Leask, Graham escreveu: > Hi Rui, > > Thank you f

Re: [R] Replace missing value within group with non-missing value

2013-04-06 Thread Rui Barradas
Hello, Can't you post a data example? If your dataset is named 'dat' use dput(head(dat, 50)) # paste the output of this in a post Rui Barradas Em 06-04-2013 15:34, Leask, Graham escreveu: Hi Rui, Thank you for your suggestion which is very much appreciated. Unfortunately running this code

Re: [R] Replace missing value within group with non-missing value

2013-04-06 Thread Leask, Graham
Hi Rui, Thank you for your suggestion which is very much appreciated. Unfortunately running this code produces the following error. error in '$<-.data.frame' ('*tmp*', "mth", value = NA_real_) : replacement has 1 rows, data has 0 I'm sure there must be an elegant solution to this problem?

Re: [R] Replace missing value within group with non-missing value

2013-04-06 Thread Rui Barradas
Hello, That's not a very good way of posting your data, preferably paste the output of ?dput in a post. Some thing along the lines of the following might do what you want. It seems that the groups are established by 'dn' and 'obs' numbers. If so, try # Make up some data dat <- data.frame(dn

[R] Replace missing value within group with non-missing value

2013-04-06 Thread Leask, Graham
Dear List members I have a large dataset organised in choice groups see sample below +-+ | dn obs choice acid br date cdate situat~n mth year set |