2. Upload CSV sheet. read.csv is the base R function,
and read_csv is the tidyverse function which automatically
reads in your CSV as a tibble.
# Read data from a csv file. Here, I used `read_csv` [notice underscore] so that my file is imported as a tibble.
df <- read_csv("20230726_h2l2c_demo_tables_together.csv")
## Rows: 13 Columns: 7
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (6): name, eye_color, driver, height, units, fave_pet
## dbl (1): age
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# View our new dataframe
#View(df)
3. Different ways to view data
#use the dollar sign to specify your column
df$name
## [1] "Garima" "Kalynn" "Bhavyaa" "Yijun" "Johanna" "Matthew" "Nyssa"
## [8] "Jenna" "Meghan" "Nikolas" "Cindy" "Devin" "Gabi"
df$units
## [1] "cm" "ft" "ft" "celsius" "in" "cm" "cm"
## [8] "cm" "in" "cm" "cm" "cm" "cm"
df$eye_color
## [1] "brown" "green" "black" "brown" "hazel" "blue" "blue" "hazel" "blue"
## [10] "Brown" "brown" "Hazel" "Green"
#or use brackets in the notation [row,column]
#if you don't specify the row, it will take all rows
#if you don't specify column, it will take all columns
#df row 1, all columns
df[1,]
#df row 8, all columns
df[8,]
#df column 1, all rows
df[,1]
#df column 5, all rows
df[,5]
#df row 1, column 7
df[1,7]
4. Try different descriptives to understand your df
#get counts of rows and columns
nrow(df)
## [1] 13
ncol(df)
## [1] 7
#use table() to get a COUNT of your represented categories
#this is also a shortcut to see WHAT categories you have in your data
table(df$age)
##
## 21 23 24 25 27 28 29 32
## 1 1 1 2 2 1 4 1
table(df$driver)
##
## yes Yes
## 12 1
table(df$fave_pet)
##
## cat dog none Sally turtle
## 2 8 1 1 1