Podcast
Questions and Answers
Which command is used to remove all objects from the R workspace?
Which command is used to remove all objects from the R workspace?
- rm(list=ls(all=TRUE)) (correct)
- remove.objects()
- rm(list=all)
- clear()
The function mean() can be used to calculate the median of a set of numbers.
The function mean() can be used to calculate the median of a set of numbers.
False (B)
What is the syntax to create a vector called 'y' containing the values 1, 5, 4, and 8?
What is the syntax to create a vector called 'y' containing the values 1, 5, 4, and 8?
y=c(1,5,4,8)
The function used to load a saved workspace in R is called _____
The function used to load a saved workspace in R is called _____
Match the following R commands with their functions:
Match the following R commands with their functions:
Which function would you use to check for missing values in a dataset?
Which function would you use to check for missing values in a dataset?
The function na.omit()
removes rows that contain any missing values.
The function na.omit()
removes rows that contain any missing values.
What is the main purpose of the complete.cases()
function?
What is the main purpose of the complete.cases()
function?
To create a dataframe in R using vectors for age, gender, and weight, you would use the function data.frame()
with the vectors named as ___.
To create a dataframe in R using vectors for age, gender, and weight, you would use the function data.frame()
with the vectors named as ___.
Match the following R functions with their purposes:
Match the following R functions with their purposes:
What command is used to install the Ecdat package in R?
What command is used to install the Ecdat package in R?
The command library('datasets')
is used to load the datasets package into the R workspace.
The command library('datasets')
is used to load the datasets package into the R workspace.
How can you access the weight of the first individual in the 'data' dataframe created from age, gender, and weight vectors?
How can you access the weight of the first individual in the 'data' dataframe created from age, gender, and weight vectors?
What happens when you execute 'mean(y, na.rm = TRUE)' in R?
What happens when you execute 'mean(y, na.rm = TRUE)' in R?
A dataframe in R can be created by importing text or Excel files.
A dataframe in R can be created by importing text or Excel files.
What function is used to import a text file into R?
What function is used to import a text file into R?
The command to display the first six rows of a dataframe is ____.
The command to display the first six rows of a dataframe is ____.
Match the following dataframe functions with their purposes:
Match the following dataframe functions with their purposes:
When importing a dataframe from an Excel file, what is the first step you should take in RStudio?
When importing a dataframe from an Excel file, what is the first step you should take in RStudio?
The function 'merge()' is used to sort a dataframe according to a variable.
The function 'merge()' is used to sort a dataframe according to a variable.
What would be the output of 'class(nobel)' after importing the dataframe?
What would be the output of 'class(nobel)' after importing the dataframe?
To create a vector in R containing the values 29020, 32500, and 40320, one could use the command ____.
To create a vector in R containing the values 29020, 32500, and 40320, one could use the command ____.
Which of the following statements regarding dataframes is false?
Which of the following statements regarding dataframes is false?
Flashcards
Dataframe in R
Dataframe in R
A data structure in R that stores a table of data, with rows representing observations and columns representing variables.
Creating a dataframe
Creating a dataframe
Methods to create a dataframe in R include importing from files (text or excel), direct creation, or using existing data.
Importing from text/Excel
Importing from text/Excel
A method to create a dataframe in R by reading data from text files, comma separated value (csv) files, or spreadsheet files. Commonly used for data load.
read.table function
read.table function
Signup and view all the flashcards
dataframe dimensions
dataframe dimensions
Signup and view all the flashcards
Row/Column Names
Row/Column Names
Signup and view all the flashcards
head() function
head() function
Signup and view all the flashcards
tail() function
tail() function
Signup and view all the flashcards
subset()
subset()
Signup and view all the flashcards
merge()
merge()
Signup and view all the flashcards
order() function
order() function
Signup and view all the flashcards
NA value in R
NA value in R
Signup and view all the flashcards
Managing Missing Values
Managing Missing Values
Signup and view all the flashcards
R Database
R Database
Signup and view all the flashcards
R Workspace
R Workspace
Signup and view all the flashcards
is.na()
is.na()
Signup and view all the flashcards
complete.cases()
complete.cases()
Signup and view all the flashcards
ls()
ls()
Signup and view all the flashcards
rm(list=ls(all=TRUE))
rm(list=ls(all=TRUE))
Signup and view all the flashcards
na.omit()
na.omit()
Signup and view all the flashcards
Subset(dataframe)
Subset(dataframe)
Signup and view all the flashcards
getwd()
getwd()
Signup and view all the flashcards
setwd()
setwd()
Signup and view all the flashcards
Dataframe generation
Dataframe generation
Signup and view all the flashcards
save.image()
save.image()
Signup and view all the flashcards
Dataframe variables
Dataframe variables
Signup and view all the flashcards
load()
load()
Signup and view all the flashcards
mtcars data
mtcars data
Signup and view all the flashcards
Variable (in R)
Variable (in R)
Signup and view all the flashcards
chicken data
chicken data
Signup and view all the flashcards
quakes data
quakes data
Signup and view all the flashcards
Vector (in R)
Vector (in R)
Signup and view all the flashcards
Ecdat package
Ecdat package
Signup and view all the flashcards
Class of object (in R)
Class of object (in R)
Signup and view all the flashcards
cbind()
cbind()
Signup and view all the flashcards
DoctorAUS data
DoctorAUS data
Signup and view all the flashcards
Dataset Search Tool
Dataset Search Tool
Signup and view all the flashcards
rbind()
rbind()
Signup and view all the flashcards
Function (in R)
Function (in R)
Signup and view all the flashcards
mean()
mean()
Signup and view all the flashcards
NA (in R)
NA (in R)
Signup and view all the flashcards
Study Notes
Data Analysis using R
- R is a programming language and software environment for statistical computing and graphics
- RStudio is a desktop environment for R
- R Data analysis involves creating, uploading and using a database in R
- Workspace in RStudio includes variables, mathematical vectors, matrices, lists, and dataframes
- To show objects in a workspace, use
ls()
. - To remove all objects in a workspace use
rm(list=ls(all=TRUE))
- To select a folder for saving the workspace use
getwd()
andsetwd("C:/name/name/name")
- To save the workspace to a file use
save.image("name.Rdata")
- To load the saved workspace use
load("name.Rdata")
- Variables are assigned values using the equal sign (
=
) for example,x = 1
. class(x)
shows the object type.- A vector is created using
y=c(1,5,4,8)
. - The command
class(y)
displays the object type - Matrices can be created from vectors using functions like
rbind()
andcbind()
for examplem = rbind(y, z)
. - R functions are used for importing and exporting data, performing operations, generating graphs
- Functions generally use the form
function_name(par1=value1, par2=value2, …)
- Using
?mean
displays the help for themean
function - Using the
is.na()
function indicates missing values, like missing data is denotedNA
(Not Applicable) in R mean(y, na.rm = TRUE)
removes NAs when calculating mean.- A dataframe is a table with observations in rows and variables in columns
- Dataframes can be created in R by importing from a
text
orexcel
file - The
read.table
function allows importingtext
files.header = TRUE
shows that the first row contains column names
Dataframe Basic Functions
dim()
shows the number of observations and variables.rownames()
shows names of rows.colnames()
shows names of columns.head()
displays the first six rows of a dataframe.tail()
displays the last six rows of a dataframe
Dataframe Advanced Functions
subset()
is used to select sections of a dataframesubset(dataframe, subset = logical_expression, select = list_of_variables)
merge(df1, df2, by = list_of_variables, by.x = ,by.y = ,….)
joins two dataframes.df[order(df$nom_var),]
sorts the dataframe based on a column named "nom_var".
Exercise: Age and Creativity of Researchers
- Calculate the age in which scientists are highly creative using
year_research_mid
andyear_birth
data - Calculate the average age using the
mean()
function - Dataframes to include Nobel prize winners' characteristics, including the year when research was conducted and year of birth
Exercise 2: Age and Creativity of Researchers
- Calculate the average age at which scientists did their research before 1905.
- Calculate the average age at which scientists did their research after 1985.
Exercise 3: Lifespan Calculation
- Calculate the lifespan of each research using the difference between their birth year and death year (
nobel$year_death - nobel$year_birth
). - Calculate the average lifespan using the
mean()
function on the new lifespan column.
Managing Missing Values
- Problem in calculating the average lifespan with missing value.
is.na()
identifies missing values.complete.cases()
selects rows without missing values.na.omit()
removes rows with any missing values.
2) Dataframe Generation
- Create a dataframe from sample data including age, gender, and weight of 5 individuals
3) Dataframes in R or Database Packages
- Various data packages already existing in R
Example 1: Motor Trend US Magazine
- Data on 32 car models (1973–74)
- A table of their data
Example 2: Weight and Food of Chickens in a Chicken Coop
- Data on the weight and feed of chickens
Example 3: Earthquake Magnitude in Fiji
- Data displaying distribution of earthquake magnitudes near Fiji from 1964
New Tool: Google Dataset Search
- Online tool for searching data sets
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
This quiz explores the fundamentals of data analysis using R programming and RStudio. Participants will review concepts such as workspace management, data handling, and object manipulation. Test your knowledge on how to effectively create and manage datasets in R.