Re: [R] Vector indices

From: Berton Gunter <gunter.berton_at_gene.com>
Date: Wed 18 Jan 2006 - 07:54:17 EST


As you apparently haven't received any answer yet ...

Assuming your "table" is a data frame (str() will tell you), I believe you are confusing the row names with indices. Please read the docs on data frame for details (?data.frame). Row names are character strings that can be indexed as such:

> test<-data.frame(x=1:4,y=letters[1:4])
> row.names(test)

[1] "1" "2" "3" "4"

> test

  x y
1 1 a
2 2 b
3 3 c
4 4 d

> test[2,]

  x y
2 2 b

> test['2',]

  x y
2 2 b

> test[2,1]<-NA
> test

   x y
1 1 a
2 NA b
3 3 c
4 4 d

> test2<-na.omit(test)
> test2

  x y
1 1 a
3 3 c
4 4 d

> test2[2,]

  x y
3 3 c

> test2['2',]

    x y
NA NA <NA>

> test2['3',]

  x y
3 3 c

"The business of the statistician is to catalyze the scientific learning process." - George E. P. Box    

> -----Original Message-----
> From: r-help-bounces@stat.math.ethz.ch
> [mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Werner
> Wernersen
> Sent: Tuesday, January 17, 2006 10:23 AM
> To: r-help@stat.math.ethz.ch
> Subject: [R] Vector indices
>
> Hi,
>
> I am despairing of getting the indices for a vector:
> First, I have a table from which I kick out a number of
> rows with na.omit. Next, I use this table for clustering
> with kmeans and cl$cluster contains my clusters. The
> cl$cluster is a vector which still contains my original
> indices from the very beginning, a kind of like an
> "associative" array. But how can I get a list of only these
> indices? When I use which() on the data it returns new
> indices starting from 1 to N together with the "old" indices
> but the "old" ones remain unaccessible.
>
> It would be great if someone could give me a hand with that.
>
> Thanks,
> Werner
>
>
>
> ---------------------------------
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Jan 18 08:13:22 2006

This archive was generated by hypermail 2.1.8 : Wed 18 Jan 2006 - 14:08:38 EST