Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Chapter 2:

Getting started
with R
Working with directory
• getwd()
getwd() command returns the absolute filepath of the current working directory.

• setwd()
setwd() command resets the current working directory to another location as per
users’ preference.

• dir()
This function returns a character vector of the names of files or directories in the
named directory.
Data types in R
Data type essentially means the kind of value which can be stored such as Boolean,
numbers, characters etc.

Data types supported by R.


• Logical
• Numeric
• Integer
• Character
• Double
• Complex
• Raw
Load Internal Dataset

• Follow the below steps to load the dataset, “mtcars”.


• Check if the package, “datasets” is already installed.

• If already installed and will be used frequently, load the package.


Few Commands for Data Exploration contd…
• head()
head() command displays the first ‘n’ observations from the given data
frame.

• tail()
tail() command displays the last ‘n’ observations from a given data frame.

• edit()
edit() command helps with dynamic editing/data manipulation to a dataset.
Few Commands for Data Exploration contd…

• summary()
summary() command includes functions like min, max, median, mean,
etc., for each variable present in the given data frame.

• str()
str() command displays the internal structure of a data frame.

• View()
View() command displays the given data set in a spreadsheet-like data
frame viewer.
• For calculating average
• #mean()

• For calculating quartile # quantile( data, probs)


• Example a=c(11,11,13,15,15)
• quantile( a, 0.25)

• For calculating # percentile # quantile( data, c(0.11)


quantile( data, c(0.11))

• For Variance calculation


Var()

• For Standard deviation


Sd()

You might also like