Indexing and looping over lists in R, a tutorial (CC174)

preview_player
Показать описание
Lists are an important, but underappreciated type of data in R. In this Code Club, Pat gives a tutorial on indexing or accessing values from a list and then shows how we can iterate over the values of a list using the lapply function. Along the way we'll see how we can unlist lists and convert them into matrices as well as generate the transpose of a matrix with the t function. This is part of a series of videos demonstrating how to functions from base R to make these data compatible with tools from the tidyverse

#list #lapply #R #Rstats #baseR

You can also find complete tutorials for learning R with the tidyverse using...

0:00 Using lists and lapply to replace a for loop
1:31 Parsing a file on line breaks with scan
3:53 Splitting text data with strsplit
5:57 How to access values from a list
8:35 Creating a function to make list elements the same length
11:43 Iterating a function over values in a list with lapply
16:14 Converting lower triangular matrix to a full matrix
Рекомендации по теме
Комментарии
Автор

Wow! Thanks Pat. This was the most advanced episode in the series and it requires one to be well versed in the intricacies of base R. Thoroughly enjoyed it!

mocabeentrill
Автор

Your explanation that dataframes are actually lists of vectors blew my mind. None of my instructors have ever made that explicit!

CBG
Автор

Learning a lot from your videos. Happy holidays!

Автор

Merry xmas. Thx for the videos of this year

luisandresmorenocueva
Автор

very interesting lessons .. congrats from Argentina

marcossahade
Автор

Hi, thanks a lot for the great content.
I don't seem to be able to explain why they included [, 1] in the code below. I was checking a solved exercise and found this code, so I thought I could maybe ask here about the theoretical explanation behind that specific part. I would have thought that Data[, i] was enough to make it work. Thanks in advance.

for(i in c(2, 6:11)){
a=(abs(scale(Data[, i])[, 1])<3)
Data=Data[a, ]
}

domenicoscarpino