Chapter 2 | Exercise 3
Create a character vector with the names of your fellow students or friends. Create a numeric vector with their heights (alternatively, the number of siblings, ages, etc.). Combine this information in one data frame.
Create a character vector with the first names. For example:
> firstnames <- c("Anna", "Brad", "Caren", "Doug", "Emma")
> firstnames
[1] "Anna" "Brad" "Caren" "Doug" "Emma"
Create a numeric vector with the heights. For example:
> heights <- c(168, 185, 159, 174, 171)
> heights
[1] 168 185 159 174 171
Now create a data frame:
> friends <- data.frame(firstnames, heights)
> friends
firstnames heights
1 Anna 168
2 Brad 185
3 Caren 159
4 Doug 174
5 Emma 171
Note that the character vector by default becomes a factor.