Skip to content

Commit

Permalink
updated L02
Browse files Browse the repository at this point in the history
  • Loading branch information
january3 committed Sep 17, 2024
1 parent f443863 commit fcebc71
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Lectures/lecture_02.html

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions Lectures/lecture_02.rmd
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,21 @@ There is a shortcut:
person$name
```

## Creating and removing elements


You can add elements to a list using the `$` operator:

```{r eval=FALSE,echo=T}
person$city <- c("Berlin", "Hoppegarten")
```

You can remove elements by assigning the NULL value to them:

```{r eval=FALSE,echo=T}
person$city <- NULL
```

## Accessing lists {.columns-2}

![](images/clothesline_2.png){ height=300px }
Expand Down Expand Up @@ -364,6 +379,20 @@ However, note that when you select a row, you will get a data frame, not a
vector. This is because each of the column can be of different type, and
vectors can hold only one type of data.

## Creating new columns and removing columns

You can add new columns to a data frame using the `$` operator:

```{r}
d$city <- c("Hoppegarten", "Berlin", "Seattle")
```

You can remove columns by assigning the NULL value to them:

```{r}
d$city <- NULL
```

## Matrices vs data frames

Caveats:
Expand Down

0 comments on commit fcebc71

Please sign in to comment.