Articles by John Akwei

Multivariate Apply Exercises

January 17, 2017 | John Akwei

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 | John Akwei

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 ... [Read more...]

Applying Functions To Lists Exercises

September 19, 2016 | John Akwei

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 | John Akwei

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 | John Akwei

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 ... [Read more...]

Interactive Subsetting Exercises

July 29, 2016 | John Akwei

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[,1]“, for values greater than “15.0“. Exercise 2 Subset the dataframe, “mtcars” ... [Read more...]

As.Date() Exercises

July 14, 2016 | John Akwei

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 ... [Read more...]

Data Shape Transformation With Reshape()

July 6, 2016 | John Akwei

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 | John Akwei

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” ... [Read more...]

Scripting Loops In R

June 1, 2016 | John Akwei

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 ... [Read more...]

Accessing Dataframe Objects Exercises

May 20, 2016 | John Akwei

The attach() function alters the R environment search path by making dataframe variables into global variables. If incorrectly scripted, the attach() function might create symantic errors. To prevent this possibility, detach() is needed to reset the dataframe objects in the search path. The transform() function allows for transformation of dataframe ... [Read more...]

Cross Tabulation with Xtabs exercises

May 12, 2016 | John Akwei

The xtabs() function creates contingency tables in frequency-weighted format. Use xtabs() when you want to numerically study the distribution of one categorical variable, or the relationship between two categorical variables. Categorical variables are also called “factor” variables in R. Using a formula interface, xtabs() can create a contingency table, (also ... [Read more...]

Complex Tables – Exercises

April 26, 2016 | John Akwei

The ftable() function combines Cross-Tabulation with the ability to format , or “flatten”, contingency tables of 3 or more dimensions. The resulting tables contain the combined counts of the categorical variables, (also factor variables in R), that are then arranged as a matrix, whose rows and columns correspond to the original data’... [Read more...]

Data Exploration with Tables exercises

April 20, 2016 | John Akwei

The table() function is intended for use during the Data Exploration phase of Data Analysis. The table() function performs categorical tabulation of data. In the R programming language, “categorical” variables are also called “factor” variables. The tabulation of data categories allows for Cross-Validation of data. Thereby, finding possible flaws within ... [Read more...]

Merging Dataframes Exercises

April 14, 2016 | John Akwei

When combining separate dataframes, (in the R programming language), into a single dataframe, using the cbind() function usually requires use of the “Match()” function. To simulate the database joining functionality in SQL, the “Merge()” function in R accomplishes dataframe merging with the following protocols; “Inner Join” where the left table ... [Read more...]

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)