Warning: Parameter 2 to wp_hide_post_Public::query_posts_join() expected to be a reference, value given in /home/rexercis/public_html/wp-includes/class-wp-hook.php on line 286
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.
Create a list called
x with two elements; two vectors of length 1 called
b whose value is 1 and 2 respectively.
Add a third vector of length 1 to
z = 3.
Turn your list into a named vector called
y with only one line of code.
Create a new list
z which contains two vectors,
y and another one with 100 random standard normal numbers.
With one line of code extract the median from each of the vectors in
Create a new list
w containing the dataset iris and
z, make sure each element is named. Now, using
w extract the
Petal.width vector. Note that the iris dataset is available in R by default, just type iris in the console.
c from the list
x from question 2.
Create a new list using the following code:
dfs <- list( df1 = data.frame(s="a", t=1:5), df2 = data.frame(s="b", t=111:115), df3 = data.frame(s="c", t=300:310) ) Using
do.call()bind them toegher in one master
df2 from the list (
dfs) using the following syntax
"[["(a, b) with the right arguments
Using a similar call as above, make a new
data.frame consisting of rows 3:4 from each of the data.frames in
(Picture by Shaofu Ku)
- Become a Top R Programmer Fast with our Individual Coaching Program
- Explore all our (>4000) R exercises
- Find an R course using our R Course Finder directory
- Subscribe to receive weekly updates and bonus sets by email
- Share with your friends and colleagues using the buttons below