Skip to content

Commit

Permalink
adds data frame creation to m7
Browse files Browse the repository at this point in the history
  • Loading branch information
wzbillings committed Jul 15, 2024
1 parent 4fd0133 commit 8320d37
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions modules/Module07-VarCreationClassesSummaries.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,19 @@ You can transform an existing matrix into data frames using `as.data.frame()`
as.data.frame(matrix(1:6, ncol = 2) )
```

You can create a new data frame out of vectors (and potentially lists, but
this is an advanced feature and unusual) by using the `data.frame()` function.
Recall that all of the vectors that make up a data frame must be the same
length.

```{r}
lotr <-
data.frame(
name = c("Frodo", "Sam", "Aragorn", "Legolas", "Gimli"),
race = c("Hobbit", "Hobbit", "Human", "Elf", "Dwarf"),
age = c(53, 38, 87, 2931, 139)
)
```

## Numeric variable data summary

Expand All @@ -331,9 +344,9 @@ Data summarization on numeric vectors/variables:
- `colSums()`: get the columns sums of a data frame
- `rowSums()`: get the row sums of a data frame
- `colMeans()`: get the columns means of a data frame
- `rowMeans`()`: get the row means of a data frame
- `rowMeans()`: get the row means of a data frame

Note, the top 8 functions have an `na.rm` **argument for missing data**
Note, all of these functions have an `na.rm` **argument for missing data**.

## Numeric variable data summary

Expand Down

0 comments on commit 8320d37

Please sign in to comment.