Yet another way which returns the row and column of the items you want
rc <- which(t(x[,-c(1,ncol(x))]),arr.ind=TRUE) #this identifies the rows and
columns but is one column off
rc[,1] <- rc[,1] +1 #this adjusts the columns
colnames(rc) <- c("col","row")
rc #show them
Bill
On Jun 6, 2014, at 5:27 PM, ONKELINX, Thierry <[email protected]> wrote:
> Here is my solution.
>
> falses <- which(!x)
> first.false <- head(falses, 1)
> last.false <- tail(falses, 1)
> which(x[first.false:last.false]) + first.false - 1
>
>
> Best regards,
>
> ir. Thierry Onkelinx
> Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
> Forest
> team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
> Kliniekstraat 25
> 1070 Anderlecht
> Belgium
> + 32 2 525 02 51
> + 32 54 43 61 85
> [email protected]
> www.inbo.be
> To call in the statistician after the experiment is done may be no more than
> asking him to perform a post-mortem examination: he may be able to say what
> the experiment died of. ~ Sir Ronald Aylmer Fisher
> The plural of anecdote is not data. ~ Roger Brinner
> The combination of some data and an aching desire for an answer does not
> ensure that a reasonable answer can be extracted from a given body of data. ~
> John Tukey
>
> ________________________________________
> Van: [email protected] [[email protected]] namens
> Fisher Dennis [[email protected]]
> Verzonden: vrijdag 6 juni 2014 23:45
> Aan: [email protected]
> Onderwerp: [R] Identifying one or more TRUE in the middle of an array
>
> R 3.1.0
> OS X
>
> Colleagues
>
> I have an array (I am using T/F rather than TRUE/FALSE for convenience) that
> could have patterns like:
> c(T, T, T, F, F, F, T, F, T, T, T) ## T at either end, a
> single T in the middle
> c(F, F, F, F, F, T, F, F, T, T, T) ## T at the tail end,
> a single T in the middle
> c(T, T, T, F, F, T, T, F, F, F, F) ## T at the front end,
> two T in the middle
> c(T, T, T, F, F, T, T, F, T, F, F) ## T at the front end,
> three T in the middle (not contiguous)
> c(F, F, F, F, F, T, F, F, F, F, F) ## no T at either end,
> a single T in the middle
> There might (or might not) be one or more T at the beginning (or the end).
> There might or might not be one or more T in the middle (not in a series that
> continues to either end) and the position of these T values varies.
>
> I am trying to identify the indices (if any) of these T values in the middle
> A brute force approach would be to strip off any contiguous T values from
> each end, then look for any remaining T values. Can anyone propose a more
> clever approach?
>
> Dennis
>
> Dennis Fisher MD
> P < (The "P Less Than" Company)
> Phone: 1-866-PLessThan (1-866-753-7784)
> Fax: 1-866-PLessThan (1-866-753-7784)
> www.PLessThan.com
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [email protected] 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.
> * * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * *
> Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer
> en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd
> is door een geldig ondertekend document.
> The views expressed in this message and any annex are purely those of the
> writer and may not be regarded as stating an official position of INBO, as
> long as the message is not confirmed by a duly signed document.
>
> ______________________________________________
> [email protected] 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.
>
William Revelle http://personality-project.org/revelle.html
Professor http://personality-project.org
Department of Psychology http://www.wcas.northwestern.edu/psych/
Northwestern University http://www.northwestern.edu/
Use R for psychology http://personality-project.org/r
It is 5 minutes to midnight http://www.thebulletin.org
______________________________________________
[email protected] 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.