When I first started learning R, it seemed way more complicated than what I was used to with looking at spreadsheets in Microsoft Excel. When I started working with data frames in R, it didn’t seem quite as easy to know what I was looking at. I’ve since come to see the light. While there is a bit of a learning curve to get a handle on it, viewing data in R is infinitely more flexible than doing so in Excel. In this post, I’ll
cover the most basic R functions for examining a data set and explain why they’re important. Understanding how to get a simple overview of the data set has become a huge time saver for me. If you aren’t familiar with these functions, you need to be. If you’re anything like me, you’ll use them first for every single data set you consider. All of the functions I’m discussing here come in the base R Utils package, so there’s no need to install any additional packages. Here are the functions, with links to their documentation:
Now, let’s import a data set see how each of these functions works. First, here’s the code: ### Import a data set on violent crime by state and assign it to the data frame "crime" crime <- read.csv("http://vincentarelbundock.github.io/Rdatasets/csv/datasets/USArrests.csv", stringsAsFactors = FALSE) ### Call the functions on crime to examine the data frame dim(crime) str(crime) summary(crime) colnames(crime) ### The head() and tail() functions default to 6 rows, but we can adjust the number of rows using the "n = " argument head(crime, n = 10) tail(crime, n = 5) ### While the first 6 functions are printed to the console, the View() function opens a table in another window View(crime) Now, let’s take a look at the output, so we can see what happens when the code is run. First, we’ll look at the dim(), str(), summary(), and colnames() functions:
Now, let’s take a look at the head() and tail() functions:
Finally, let’s take a look at the window that appears when we call the View() function:
That’s it! Getting comfortable with these functions should make it easier for you to work with data frames in a more logical and efficient manner. Happy viewing! Which of the following function cross tabulate tables using formula?Which of the following function cross-tabulate tables using formulas? Explanation: table() list all values of a variable with frequencies.
Which of the following functions in R is used to represent 1 D plot of the data to an existing plot?Explanation: Scatterplots would be used frequently for particular dimension.
Which of the following plots are used to check if a data set or time series is random lag random lead none of the mentioned?Lag plots are used to check if a data set or time series is random. Random data should not exhibit any structure in the lag plot.
What is a data frame and a matrix in R Mcq?Explanation: Data frames are tabular data objects. Unlike a matrix in each data frame every column will contain different modes of data. Data Frames are created using the data. frame() function. It is the list of vectors of same length.
|