Blog Archives

Multivariate Apply Exercises

January 17, 2017
By
Multivariate Apply Exercises

mapply() works with multivariate arrays, and applys a function to a set of vector or list arguments. mapply() also simplifies the output. Structure of the mapply() function: mapply(FUN, ..., MoreArgs = NULL, SIMPLIFY = TRUE, USE.NAMES = TRUE) Answers to the exercises are available here. Exercise 1 Beginning level Required dataframe: PersonnelData

Read more »

Optimize Data Exploration With Sapply() – Exercises

October 14, 2016
By
Optimize Data Exploration With Sapply() – Exercises

The apply() functions in R are a utilization of the Split-Apply-Combine strategy for Data Analysis, and are a faster alternative to writing loops. The sapply() function applies a function to individual values of a dataframe, and simplifies the output. Structure of the sapply() function: sapply(data, function, ...) The dataframe used for these exercises: dataset1

Read more »

Applying Functions To Lists Exercises

September 19, 2016
By
Applying Functions To Lists Exercises

The lapply() function applies a function to individual values of a list, and is a faster alternative to writing loops. Structure of the lapply() function: lapply(LIST, FUNCTION, ...) The list variable used for these exercises: list1

Read more »

Efficient Processing With Apply() Exercises

September 8, 2016
By
Efficient Processing With Apply() Exercises

The apply() function is an alternative to writing loops, via applying a function to columns, rows, or individual values of an array or matrix. The structure of the apply() function is: apply(X, MARGIN, FUN, ...) The matrix variable used for the exercises is: dataset1

Read more »

Reshape 2 Exercises

August 26, 2016
By
Reshape 2 Exercises

The Reshape 2 package is based on differentiating between identification variables, and measurement variables. The functions of the Reshape 2 package then “melt” datasets from wide to long format, and “cast” datasets from long to wide format. Required package: library(reshape2) Answers to the exercises are available here. Exercise 1 Set a variable called “moltenMtcars“, by

Read more »

Interactive Subsetting Exercises

July 29, 2016
By
Interactive Subsetting Exercises

The function, “subset()” is intended as a convienent, interactive substitute for subsetting with brackets. subset() extracts subsets of matrices, data frames, or vectors (including lists), according to specified conditions. Answers to the exercises are available here. Exercise 1 Subset the vector, “mtcars“, for values greater than “15.0“. Exercise 2 Subset the dataframe, “mtcars” for rows

Read more »

As.Date() Exercises

July 14, 2016
By
As.Date() Exercises

The as.date() function creates objects of the class “Date“, via input of character representations of dates. Answers to the exercises are available here. Exercise 1 The format of as.Date(x, ...) accepts character dates in the format, “YYYY-MM-DD”. For the first exercise, use the c() function, and as.date(), to convert “2010-05-01” and “2004-03-15” to class “date”

Read more »

Data Shape Transformation With Reshape()

July 6, 2016
By
Data Shape Transformation With Reshape()

reshape() is an R function that accesses “observations” in grouped dataset columns and “records” in dataset rows, in order to programmatically transform the dataset shape into “long” or “wide” format. Required dataframe: data1

Read more »

Summary Statistics With Aggregate()

June 16, 2016
By
Summary Statistics With Aggregate()

The aggregate() function subsets dataframes, and time series data, then computes summary statistics. The structure of the aggregate() function is aggregate(x, by, FUN). Answers to the exercises are available here. Exercise 1 Aggregate the “airquality” data by “airquality$Month“, returning means on each of the numeric variables. Also, remove “NA” values. Exercise 2 Aggregate the “airquality”

Read more »

Scripting Loops In R

June 1, 2016
By
Scripting Loops In R

An R programmer can determine the order of processing of commands, via use of the control statements; repeat{}, while(), for(), break, and next Answers to the exercises are available here. Exercise 1 The repeat{} loop processes a block of code until the condition specified by the break statement, (that is mandatory within the repeat{} loop),

Read more »

Search R-bloggers


Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)