Re: [R] index

From: <Richard.Cotton_at_hsl.gov.uk>
Date: Wed, 2 Jan 2008 16:06:21 +0000


> I would like to know if it?s possible to create an index for a
> variable/vector that specifies the value in the n position before
> the actual value.
>
> For example, if X <- c(letters[1:10]), x[10] is ?j?. I would like to
> create an index exp3 (the third position before) such as if z <-
> x[exp3], then z[10] = ?g?.

x<- letters[1:10]

Then either
z<- c(rep(NA,3), x)
z[10] #"g"

or
exp3<- 1:length(x) - 3; exp3[exp3<=0] <- NA z <- x[exp3]
z[10] #"g"

Regards,
Richie.

Mathematical Sciences Unit
HSL



ATTENTION: This message contains privileged and confidential inform...{{dropped:21}}

R-help_at_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. Received on Wed 02 Jan 2008 - 16:11:29 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 02 Jan 2008 - 16:30:04 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive