[R] behavior of seq_along
dwinsemius at comcast.net
Thu Feb 25 15:55:18 CET 2010
On Feb 25, 2010, at 9:02 AM, Dale Steele wrote:
> I'm trying to understand the behavior of seq_along in the following
> x <- 1:5; sum(x)
> y <- 6:10; sum(y)
> data <- c(x,y)
> S <- sum( data[seq_along(x)] )
> T <- sum( data[seq_along(y)] )
> Why is T != sum(y) ?
seq_along returns indices for the purpose of accession of elements, so
it starts with 1 and ends with the length of the object.
Had you asked for sum(data[y[seq_along(y)]]) you might have achieved
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD
West Hartford, CT
More information about the R-help