[R] edit.row.names taking row names from the edited dataframe

Chuck Cleland ccleland at optonline.net
Thu Jul 30 20:57:15 CEST 2009


On 7/30/2009 2:46 PM, Ross Culloch wrote:
> Hi all,
> 
> I am struggling to work out how to use the rownames from an edited dataframe
> rather than the row names from the original dataframe. In my data set i'm
> trying to extract several rows of data on particular individuals, i don't
> doubt i'm using the long way round but what i have in the way of a script is
> this:
> 
> 
> ##selecting the IDs from the dataframe individually
> A1<-mumpup[ID=="A1",]
> B1<-mumpup[ID=="B1",]
> B2<-mumpup[ID=="B2",]
> B3<-mumpup[ID=="B3",]
> B4<-mumpup[ID=="B4",]
> B6<-mumpup[ID=="B6",]
> B7<-mumpup[ID=="B7",]
> B8<-mumpup[ID=="B8",]
> B9<-mumpup[ID=="B9",]
> B13<-mumpup[ID=="B13",]
> C1<-mumpup[ID=="C1",]
> G1<-mumpup[ID=="G1",]
> 
> data<-rbind(A1,B1,B2,B3,B4,B6,B7,B8,B9,B13,C1,G1)
> 
> It works fine to a certain extent, the only problem being that i get are all
> the IDs in the original dataframe so if i use
> 
> summary(data$ID)
> 
> I get:
> 
>  A1  B1 B10 B13  B2  B3  B4  B6  B7  B8  B9  C1  G1  G3  H2  H9  J1  J2  J3 
> K1 
> 354 354   0 354 354 354 354 354 354 354 354 246 210   0   0   0   0   0   0  
> 0 
> 
> So it does take the data out of the dataframe but it keeps the IDs for some
> reason.
> 
> I have looked at the edit.data.frame help and i understand why it is
> happening, it is taking the rownames from the original dataframe and not the
> edit and it seems i should use edit.row.names=T in my script, but i can't
> get that to work.
> 
> Does anyone have any suggestions at all? Any help is much appreciated,

  If I understand, you may want something like this:

myIDs <- c('A1','B1','B2','B3','B4','B6','B7','B8','B9','B13','C1','G1')

subset(mumpup, ID %in% myIDs)

> Best wishes,
> 
> Ross 

-- 
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894




More information about the R-help mailing list