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
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
>
>
: [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
t;, "29", "30", "31", "32", "33", "34", "35", "36", "37",
"38", "39", "40", "41", "42", "43", "44", "45", "46", "47&qu
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
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
uot;36", "37",
"38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48",
"49", "50"), class = "data.frame")
sp <- split(dat, list(da
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
;, "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
; # ... 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)] <-
, "15",
> "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26",
> "27", "28", "29", "30", "31", "32", "
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)
#
uot;31", "32", "33", "34", "35", "36", "37",
"38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48",
"
] 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
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
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?
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
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 |
18 matches
Mail list logo