You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some data sets suited for training and testing are always loaded when starting RStudio. One of these is Orange. Use the head(), tail(), summary(), and dim() functions to take a look at the data set. Typing ?Orange will give you the help page for the data set. You can also print the entire data frame by simply typing Orange.
Now, let’s say that we are only interested in tree number 3.
First take a look at the column called Tree using the dollar sign $.
Using the == command you can find out which of the elements in this column that are equal to 3. Type
Orange$Tree==3
What you got is a vector of logical values. You can use the which() function to get which places in the vector that contains TRUE.
Using square brackets [] you can now extract the part of the data frame that contains tree number 3. Remember that inside the square brackets you first tell which rows, then which columns you want to see, and an empty space means that all should be used.
Save this in a data frame called Orange_out in your script.