Lists (aka recursive vectors) are the main data structure in R. Since lists are omnipresent (data.frames are a special sub-type) having a deeper understanding of them will make for a more enjoyable data analysis and helps avoid bugs. Solutions are available here. Exercise 1 Create a list called x with two elements; two vectors of […]

# lists and dataframes

## Protected: Bonus: Data Frame exercises

There is no excerpt because this is a protected post.

## List Vol.2 Exercises

Answers to the exercises are available here. Exercise 1 Consider 3 vectors, day, month and year: year=c(2005:2016) month=c(1:12) day=c(1:31) Define a list Date such as: Date= $year [1] 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 $month [1] 1 2 3 4 5 6 7 8 9 10 11 12 $day […]

## Data frame exercises Vol. 2

[In the exercises below we cover the basics of data frames.] Answers to the exercises are available here. For other parts of this series please follow the tag: dataframes. Exercise 1 Consider two vectors: x=seq(1,43,along.with=Id) y=seq(-20,0,along.with=Id) Create a data.frame df: >df Id Letter x y 1 1 a 1.000000 -20.000000 2 1 b 4.818182 -18.181818 […]

## 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 <- list(observationA = c(1:5, 7:3), observationB=matrix(1:6, nrow=2)) Answers to the exercises are available here. Exercise 1 Using lapply(), find […]

## Accessing Dataframe Objects Exercises

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 objects. The within() function creates […]

## Merging Dataframes Exercises

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 has matching rows from one, […]

## Data frame exercises

In the exercises below we cover the basics of data frames. Before proceeding, first read section 6.3.1 of An Introduction to R, and the help pages for the cbind, dim, str, order and cut functions. Answers to the exercises are available here. For other parts of this series please follow the tag: dataframes. Exercise 1 […]

## List exercises

In the exercises below we cover the basics of lists. Before proceeding, first read section 6.1-6.2 of An Introduction to R, and the help pages for the sum, length, strsplit, and setdiff functions. Answers to the exercises are available here. Exercise 1 If: p