Subsetting a data frame consists on obtaining some rows or columns of the full data frame, or some that meet one or several conditions. It is very usual to subset a data frame in R for analysis purposes. Consider, for instance, the following sample data frame:. You can also subset a data frame depending on the values of the columns.
As an example, you may want to make a subset with all values of the data frame where the corresponding value of the column z is greater than 5, or where the group of the w column is Group 1. You can also apply a conditional subset by column values with the subset function as follows.
Note that when using this function you can use the variable names directly. When using the subset function with a data frame you can also specify the columns you want to be returned , indicating them in the select argument.
In adition, you can use multiple subset conditions at once. Subsetting with multiple conditions is just easy as subsetting by one condition. In the following example we select the values of the column x , where the value is 1 or where it is 6. Analogously to column subset, you can subset rows of a data frame indicating the indices you want to subset as the first argument between square brackets.
Many data frames have a column of dates. In the previous example, we have downloaded a csv file. Furthermore, it is possible to download files from a sharepoint or a web application such as shiny. Do you need further guidance for the downloading of files from the web? The video does not only show another example for the application of the download. It also explains how to import this data to R or RStudio.
Please accept YouTube cookies to play this video. By accepting you will be accessing content from YouTube, a service provided by an external third party. YouTube privacy policy. Accept YouTube Content. Note that leaving the index for the rows blank indicates that we want x. Click here to report an error on this page or leave a comment. Your Name required. Your Email must be a valid email for us to receive the report!
How to cite this page. Featured on Meta. Now live: A fully responsive profile. Reducing the weight of our footer. Related Hot Network Questions. Question feed. Stack Overflow works best with JavaScript enabled. Accept all cookies Customize settings.
0コメント