Hello I have a list of row names that needs to be deleted from a data frame. how do i do that. one of the columns in the data frame contains the row names as numbers I can also select by this column(will it be easier?). Thank you -- View this message in context: http://r.789695.n4.nabble.com/how-to-delete-rows-by-a-list-of-rownames-tp3930206p3930206.html Sent from the R help mailing list archive at Nabble.com.
how to delete rows by a list of rownames
4 messages · hanansela, Brad Patrick Schneid, R. Michael Weylandt
here is one way df1 <- data.frame(c(1:20), c(21:40), c(31:50)) list1 <- c(3, 6, 20) df2 <- df1[-list1,]
hanansela wrote:
Hello I have a list of row names that needs to be deleted from a data frame. How do i do that? one of the columns in the data frame contains the row names as numbers. I can also select by this column (will it be easier?). Thank you
-- View this message in context: http://r.789695.n4.nabble.com/how-to-delete-rows-by-a-list-of-rownames-tp3930206p3930273.html Sent from the R help mailing list archive at Nabble.com.
I think that only works because the rows are ordered and have no names: try something more like this: df1 <- data.frame(1:20, 21:40, 31:50) rownames(df1) <- sample(letters, 20) toDrop <- sample(rownames(df1), 5) df1[ !(rownames(df1) %in% toDrop), ] or alternatively toKeep <- sample(rownames(df1), 5) df1[rownames(df1) %in% toKeep, ] Michael
On Sun, Oct 23, 2011 at 9:30 AM, B77S <bps0002 at auburn.edu> wrote:
here is one way df1 <- data.frame(c(1:20), c(21:40), c(31:50)) list1 <- c(3, 6, 20) df2 <- df1[-list1,] hanansela wrote:
Hello I have a list of row names that needs to be deleted from a data frame. How do i do that? one of the columns in the data frame contains the row names as numbers. I can also select by this column (will it be easier?). Thank you
-- View this message in context: http://r.789695.n4.nabble.com/how-to-delete-rows-by-a-list-of-rownames-tp3930206p3930273.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.
Thank you, Michael This is what i need. It works fine -- View this message in context: http://r.789695.n4.nabble.com/how-to-delete-rows-by-a-list-of-rownames-tp3930206p3931200.html Sent from the R help mailing list archive at Nabble.com.