Hi maybe
index <- which(is.na(dataset1$V2)) y <- dataset2$V1[index] plot(y~x) Regards Petr > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of e-letter > Sent: Thursday, March 07, 2013 8:28 AM > To: r-help@r-project.org > Subject: [R] create vector from indices interpolated values > > Readers, > > Is it possible to create a plot command based upon the indices of > missing values in a data set? > > dataset1<-read.table(text=' > 10 2 > 20 NA > 30 5 > 40 7 > 50 NA > 60 NA > 70 2 > 80 6 > 90 NA > 100 9 > ') > > dataset2<-read.table(text=' > 0.2 > 0.4 > 0.1 > 0.9 > 0.2 > 0.3 > 1.1 > 0.7 > 0.9 > 0.6 > 0.4 > ') > > The 'approx' function is used to obtain the interpolated values for > 'NA' in dataset1. > > dataset1interpolatedvalues<- > approx(dataset1,y=NULL,xout=dataset1$V1[is.na(dataset1$V2)]) > > dataset1interpolatedvalues > $x > [1] 20 50 60 90 > > $y > [1] 3.500000 5.333333 3.666667 7.500000 > > x<-dataset1interpolatedvalues$y > > How to create a vector 'y' by selecting the values in 'dataset2' using > the indices equivalent to interpolated values in 'dataset1' (i.e. > indices 2, 5, 6, 9 in dataset1)? The result of creating 'y' should be > > y > 0.4 > 0.2 > 0.3 > 0.9 > > Then the desired plot would be > > plot(y~x) > > Thanks. > > -- > r2151 > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.