Simulating Data with Purrr
Often when trying to solve a problem with data we first need to build some simulated data to see if our idea is even possible. For example, you may want to test models with data that have known differences, to see if the models are working correctly.
In this exercise, you will see how this works in purrr
by simulating data for two populations, a
and b
, from the sites: "north", "east", and "west". The two populations will be randomly drawn from a normal distribution, with different means and standard deviations.
Diese Übung ist Teil des Kurses
Foundations of Functional Programming with purrr
Anleitung zur Übung
- Create a list of site names, "north", "east", and "west".
- Then use
map()
to create a list of data frames with three columns, the first column issites
.- The second is population
a
, which has amean
of 5, a sample sizen
of 200, and ansd
of (5/2). - The third is population
b
, which has amean
of 200, a sample sizen
of 200, and ansd
of 15.
- The second is population
Interaktive Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
# List of sites north, east, and west
sites <- list(___)
# Create a list of data frames, each with a years, a, and b column
list_of_df <- map(___,
~___(___ = .x,
a = rnorm(mean = ___, n = ___, sd = ___),
b = rnorm(mean = ___, n = ___, sd = ___)))
list_of_df