Hello, Could anybody tell me how to find the index for a value which I define in an array? ie. c<-matrix(1:9,1,9) #A 1x9 matrix filled with numbers 1 - 9 in order I want to know the index for the value 5. Thanks in advance, George Chen
Jorge Ivan Velez
2009-Jan-04 06:28 UTC
[R] How do I find the index for a value in an array
Dear George,
Try this:
mat<-matrix(1:9,1,9)
which(mat==5,arr.ind=TRUE)
row col
[1,] 1 5
HTH,
Jorge
On Sun, Jan 4, 2009 at 1:21 AM, George Chen <glchen@stanford.edu> wrote:
> Hello,
> Could anybody tell me how to find the index for a value which I define in
> an array?
>
> ie.
>
> c<-matrix(1:9,1,9) #A 1x9 matrix filled with numbers 1 - 9 in order
> I want to know the index for the value 5.
>
> Thanks in advance,
>
> George Chen
>
> ______________________________________________
> 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.
>
[[alternative HTML version deleted]]
Seemingly Similar Threads
- Drawing schematics
- How do I juxtapose two lattice graphs with common X axes such that the X axes line up?
- Two different scales for the same axis in the same plot.
- question about running multiple R windows
- repeat matrix column within each array third dimension