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

Erik Iverson eiverson at NMDP.ORG
Thu Jul 30 20:55:42 CEST 2009


Hello, 

Try the following instead of your many separate assignments (I do not like to give objects the name "data", since that is the name of a built-in function). 

> ids <- subset(mumpup, id %in% c("A1", "B1", ... , "G1")) 
#in above line, fill in ... with other IDs you want

> ids$ID <- factor(ids$ID)
#remove extra factor levels, this would also work after the rbind
#if you called your object "ids" instead of "data". 

This really has nothing to do with the "row names" issue you mention, as far as I can tell.  It has to do with this: 

http://stackoverflow.com/questions/1195826/dropping-factor-levels-in-a-subsetted-data-frame-in-r

Best,
Erik Iverson 

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Ross Culloch
Sent: Thursday, July 30, 2009 1:46 PM
To: r-help at r-project.org
Subject: [R] edit.row.names taking row names from the edited dataframe


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,

Best wishes,

Ross

-- 
View this message in context: http://www.nabble.com/edit.row.names-taking-row-names-from-the-edited-dataframe-tp24744741p24744741.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help at 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.




More information about the R-help mailing list