try this:
for (i in 1:10){
Ts[is.na(Ts[, i]), i] <- Ts[is.na(Ts[, i]), 11]
}
Jim Holtman
Data Munger Guru
What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.
On Tue, Apr 29, 2014 at 4:46 AM, dila radi wrote:
> Hi all,
>
> I have thi
Hi,
Try this:
for (i in 1:10) Ts[is.na(Ts[,i]),i] <- Ts$V11[is.na(Ts[,i])]
Massimiliano
- Messaggio originale -
Da: "dila radi"
A: r-help@r-project.org
Inviato: Martedì, 29 aprile 2014 10:46:32
Oggetto: [R] Replacing NA's in the data set
Hi all,
I have this d
Hi Dila,
Try:
Ts1 <- Ts
Ts[,-11] <- lapply(Ts[,-11], function(x) {x[is.na(x)] <- Ts[is.na(x), 11]; x})
#or
Ts1[,-11][is.na(Ts1[,-11])] <-rep(Ts1[,11],10)[is.na(Ts1[,-11])]
identical(Ts,Ts1)
#[1] TRUE
A.K.
On Tuesday, April 29, 2014 8:53 AM, dila radi wrote:
Hi all,
I have this data set,
> d
Hi all,
I have this data set,
> dput(Ts)
structure(list(V1 = c(3, 17, 29, 12, 4.5, 1, 0.5, 0, 0, 0, 1.2,
1.8, 1.5, 0.5, 0, 47.7, 0.3, 0, 2, 0, 5.5, 8, 27.5, 69, 29, 24.5,
57.5, 40, 1, 14.5, 0, 0, 0, 0, 0, 0, 1.5, 2, 0, 0, 0, 0, 7, 29.5,
77, 11.5, 33, 38, 36, 8, 28, 11, 11, 0, 17, 0, 51, 0.5, 5, 0
4 matches
Mail list logo