Here's one way :
ds <- data.frame( st = runif(100), s0=runif(100),
s1=runif(100),s2=runif(100),mp=runif(100))
ds <- within( ds, {
n1 <- 1*( st>0.38 )
n2 <- numeric( length( st ) )
n2[ is.na(st) | st <= 0.38 ] <- .25
n2[ s0 == mp ] <- .25
n2[ s2 =
Dear all,
I'm learning R, with a "classical" programming background. Some hours were
necessary for me to programm the "vector" way.
Here is my dataset :
ds <- data.frame( st=runif(100), st=runif(100),s1=runif(100),mp=runif(100))
I need to generate 2 new variables. First was easy :
ds$n1 <- (ds
sonable answer can be extracted from a given body of
data.
~ John Tukey
-Oorspronkelijk bericht-
Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
Namens rafamoral
Verzonden: woensdag 14 januari 2009 23:32
Aan: r-help@r-project.org
Onderwerp: [R] Logical function to t
Dear rafamoral,
Try this:
x[is.na(x)]<-0
HTH,
Jorge
On Wed, Jan 14, 2009 at 5:32 PM, rafamoral wrote:
>
> I have a dataset which contains some missing values, and I need to replace
> them with zeros. I tried using the following:
>
> x <- matrix(data=rep(c(1,2,3,NA),6), ncol=6, nrow=6)
>
> y <-
Hello rafamoral,
Try this:
ifelse(is.na(x),0,x)
On Wed, Jan 14, 2009 at 8:32 PM, rafamoral wrote:
>
> I have a dataset which contains some missing values, and I need to replace
> them with zeros. I tried using the following:
>
> x <- matrix(data=rep(c(1,2,3,NA),6), ncol=6, nrow=6)
>
> y <- matr
I have a dataset which contains some missing values, and I need to replace
them with zeros. I tried using the following:
x <- matrix(data=rep(c(1,2,3,NA),6), ncol=6, nrow=6)
y <- matrix(data=0, ncol=ncol(x), nrow=nrow(x))
for(i in 1:nrow(x)) {
for(j in 1:ncol(x)) {
y[i,j] <- ifelse(x[i,j]==NA
6 matches
Mail list logo