Download What You Need to Know About R [eBook] PDF

TitleWhat You Need to Know About R [eBook]
TagsR (Programming Language) Data Analysis Matrix (Mathematics) Array Data Structure Integrated Development Environment
File Size1.5 MB
Total Pages62
Table of Contents
                            Cover
Copyright
About the Authors
About the Reviewer
www.PacktPub.com
Table of Contents
Preface: Overview
R Ecosystem
	Setting up the R ecosystem
		Installation
			Configuration
			Startup modes
			Workspace
		Exploring the basic constructs of R
			Operators
			Data types
			Data structures
		Installing packages
		Getting help
		Integrated Development Environments
			RStudio
			Other IDEs
		RPubs – Publishing through R
		Shiny – Web apps using R
Data Analysis
	Data analysis workflow
		Understanding our current objective
		Acquiring and understanding data
		Preparing the data
		Exploratory data analysis
		Statistical inference
		Statistical modeling with regression
R Cheat Sheets
	Data processing and transformation
		Data handling
			Basic data types
			Data structures
			General utilities
		Math and modeling
			Math and modeling utilities
			Math and modeling packages
		Plotting
			Plotting packages
	Summary
What to do next?
	Broaden your horizons with Packt
                        
Document Text Contents
Page 2

What you need to know
about R

Kick-start your journey with R

Raghav Bali
Dipanjan Sarkar

BIRMINGHAM - MUMBAI

Page 31

What you need to know about R

[ 18 ]

We will use this function on our existing mtcars data frame to transform the cyl,
vs, am, gear, and carb attributes into categorical attributes using the following
code snippet:

## perform data type transformation

categorical.vars<- c("cyl", "vs", "am", "gear", "carb")

mtcars<- to.factors(mtcars, categorical.vars)

Now, we will observe whether this data type transformation was successful using
the following snippet:

# verify transformation

str(mtcars)

We can then see the attribute details in the data frame with the transformed
data types in the following snapshot, which indicates that our transformations
were successful:

This brings us to the end of our data preparation stage, and we will now perform
some analysis on our dataset in the next section.

Exploratory data analysis
There are various data analysis techniques that can be applied to a dataset, depending
on the problem that has to be solved and the insights we want to gather. However, in
all cases, exploratory data analysis is somewhat of a prerequisite before jumping into
further advanced analyses. Exploratory data analysis is a good way to gain a deeper
understanding of our data, relationships, patterns between different attributes, and to
detect anomalies. Besides descriptive analysis, which includes generating summary
statistics, we also use visualization techniques to depict various patterns and statistics
about the data, which help us in understanding our data better. We will use some
graphical methods here to visualize various statistics that are related to our dataset.

Page 32

What you need to know about R

[ 19 ]

One basic visualization includes scatter plots where we usually have an attribute on
the x and y axes, and we plot the various data points in the two-dimensional space to
see the relationship between the attributes. We will plot a
pairs scatterplot between all possible attributes in our mtcars dataset with the
following code snippet:

# pairs plot observing relationships between variables

pairs(mtcars, panel = panel.smooth,

main = "Pairs plot for mtcars data set")

This gives us the following scatterplot, which shows the relationship between each
pair of attributes in the dataset:

A pairs scatterplot between different attributes of the mtcars dataset

Page 61

What you need to know about R

[ 48 ]

What to do next?

Broaden your horizons with Packt
If you’re interested in R, then you’ve come to the right place. We’ve got a diverse
range of products that should appeal to budding as well as proficient specialists in
the field of R.

https://www.packtpub.com/big-data-and-business-intelligence/machine-learning-r-second-edition
https://www.packtpub.com/big-data-and-business-intelligence/r-data-science
https://www.packtpub.com/big-data-and-business-intelligence/data-analysis-r
https://www.packtpub.com/big-data-and-business-intelligence/r-data-visualization-cookbook

Page 62

What you need to know about R

[ 49 ]

To learn more about R and find out what you want to learn next, visit the R technology
page at https://www.packtpub.com/tech/r

If you have any feedback on this eBook, or are struggling with something we haven’t
covered, let us know at [email protected]

Get a 50% discount on your next eBook or video from www.packtpub.com using
the code:

https://www.packtpub.com/tech/r
www.packtpub.com

Similer Documents