Hi all, I have a very simple question that I can't seem to find the answer to. How do I extract rows that meet a certain criteria from a data frame and group them into a new data frame? For example, if I want to make a new data frame that only includes rows of data for which the p values (given by one of the columns in the data frame) are less than a certain value, how do I do this? It seems that there should be a simple function that does this. I looked into getGroups from the nmle package, but am not sure how to construct the form argument correctly or even if it's the appropriate way to tackle this. Thanks in advance of your answer, Matt
Matt, Have a look at "subset" specially the examples at the end. I use it a lot. Hope it helps, Augusto -------------------------------------------- Augusto Sanabria. MSc, PhD. Mathematical Modeller Risk Research Group Geospatial & Earth Monitoring Division Geoscience Australia (www.ga.gov.au) Cnr. Jerrabomberra Av. & Hindmarsh Dr. Symonston ACT 2609 Ph. (02) 6249-9155 -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Matthew Scholz Sent: Friday, 10 March 2006 9:18 AM To: r-help at stat.math.ethz.ch Subject: [R] newbie question: grouping rows Hi all, I have a very simple question that I can't seem to find the answer to. How do I extract rows that meet a certain criteria from a data frame and group them into a new data frame? For example, if I want to make a new data frame that only includes rows of data for which the p values (given by one of the columns in the data frame) are less than a certain value, how do I do this? It seems that there should be a simple function that does this. I looked into getGroups from the nmle package, but am not sure how to construct the form argument correctly or even if it's the appropriate way to tackle this. Thanks in advance of your answer, Matt ______________________________________________ R-help at 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
You can try: new.dataframe <- my.dataframe[my.dataframe$p.value < 0.05, ] This will select all columns. Alternatively, you can specify the columns that you want after the ",". -Christos -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Matthew Scholz Sent: Thursday, March 09, 2006 5:18 PM To: r-help at stat.math.ethz.ch Subject: [R] newbie question: grouping rows Hi all, I have a very simple question that I can't seem to find the answer to. How do I extract rows that meet a certain criteria from a data frame and group them into a new data frame? For example, if I want to make a new data frame that only includes rows of data for which the p values (given by one of the columns in the data frame) are less than a certain value, how do I do this? It seems that there should be a simple function that does this. I looked into getGroups from the nmle package, but am not sure how to construct the form argument correctly or even if it's the appropriate way to tackle this. Thanks in advance of your answer, Matt ______________________________________________ R-help at 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
?subset Marc -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Matthew Scholz Sent: Thursday, March 09, 2006 2:18 PM To: r-help at stat.math.ethz.ch Subject: [R] newbie question: grouping rows Hi all, I have a very simple question that I can't seem to find the answer to. How do I extract rows that meet a certain criteria from a data frame and group them into a new data frame? For example, if I want to make a new data frame that only includes rows of data for which the p values (given by one of the columns in the data frame) are less than a certain value, how do I do this? It seems that there should be a simple function that does this. I looked into getGroups from the nmle package, but am not sure how to construct the form argument correctly or even if it's the appropriate way to tackle this. Thanks in advance of your answer, Matt ______________________________________________ R-help at 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