[R] finding the subscript of a vector fulfiiling a given condition
Pete Brecknock
Peter.Brecknock at bp.com
Tue Feb 14 19:36:58 CET 2012
galemago wrote
>
> Dear Forum,
>
> I just recently started to work with R, I´d like to know if there is a way
> to give instructions/do operations related to values with different
> subscripts within a vector.
> Let´s assume I have a vector like this:
> A="368 369 370 371 393 394 395"
> If I call "j" the subscripts of the vector I´d like to find the j value
> such that A(j+1)-A(j) is the maximum.
> This would tell me at which position of the vector I have the biggest gap.
> (the fifth in the example above)
> My problem is that I don´t find a way to define the vector subscripts as a
> variable, that I believe is what I need to solve this problem. Is that
> possible?
> Thanks a lot, hope to come back often in this forum,
> G.
>
How about ...
A <- c(368,369,370,371,393,394,395)
which.max(diff(A))
HTH
Pete
--
View this message in context: http://r.789695.n4.nabble.com/finding-the-subscript-of-a-vector-fulfiiling-a-given-condition-tp4387870p4388042.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list