[R] replacing with NA
Mintewab Bezabih
Mintewab.Bezabih at economics.gu.se
Wed May 16 18:55:21 CEST 2012
Dear R users,
I was wondering how I can replace the values of a vector with the values from in another vector in the same row
For example, how can I replace the value of x below with NA when the value of Z in the same row is NA?
x <-1:20
z<- c(11, 15, 17, 2, 18, 6, 7, NA, 12, 10,21, 25, 27, 12, 28, 16,17, NA, 12, 10)
Many thanks
Mintewab
________________________________________
Från: Mintewab Bezabih
Skickat: den 15 maj 2012 15:53
Till: r-help at r-project.org
Kopia: r-help at r-project.org
Ämne: missing observations
Dear R users,
I have missing observations in my data that I remove in my analysis. I am able to run my codes alright but I want the non missing values to be correctly identified and therefore want to tag my id vector along in my results. Since the vector of ids has no role in the analysis, I dont know how to include it.
Here is my reprducable example:and my id is the vector I want to add to the analysis somehow so that my missing values are identified. I cannot use na.action function and that is why I have to drop my missing obesevations beforehand.
library(fields)
x <-1:20
y<- runif(20)
z<- c(11, 15, 17, 2, 18, 6, 7, NA, 12, 10,21, 25, 27, 12, 28, 16,
17, NA, 12, 10)
id <-1:20
mydataset<-data.frame(x, y, z)
temperature[complete.cases(mydataset),]
x<- temperature[, c(1)]
y<- temperature[, c(2)]
z<- temperature[, c(3)]
tpsfit <- Tps(cbind(x, y), z, scale.type="unscaled")
Many thanks as always.
Regards,
Mintewab
More information about the R-help
mailing list