Lab 1F
Directions: Follow along with the slides and answer the questions in red font in your journal.
data(atu_dirty)
View(atu_dirty)
caseid
: Anonymous ID of survey taker.V1
: The age of the respondent.V2
: The gender of the respondent.V3
: Whether the person is employed full-time or part-time.V4
: Whether the person has a physical difficulty.V5
: How long the person sleeps, in minutes.V6
: How long the survey taker spent on homework, in minutes.V7
: How long the respondent spent socializing, in minutes.rename
function:atu_cleaner <- rename(atu_dirty, age = V1,
gender = V2)
atu_dirty
.
"string"
"A1B2c3"
"Hot Cocoa"
"0015"
Yes/No
variables as "1"
/"0"
.str
ucture of your data and the variable descriptions from a few slides back:
as.numeric
function.
as.numeric("3.14")
[1] 3.14
"3.14"
, but as.numeric
was able to turn it back into a number.atu_cleaner <- mutate(atu_cleaner,
age = as.numeric(age),
___ = as.numeric(___))
gender
variable uses "01"
and "02"
for "Male"
and "Female"
, respectively."Male"
and "Female"
.gender
and their counts type:tally(~gender, data = atu_cleaner)
01
' means 'Male
' and '02
' means 'Female
' then we can use the following code to recode the levels of gender.atu_cleaner <- mutate(atu_cleaner, gender =
recode(gender,
"01"="Male",
"02" = "Female"))
atu_cleaner <- mutate(atu_cleaner, gender =
recode(gender, "01"="Male",
"02" = "Female"))
atu_cleaner
…gender
variable's levels …"01"
will now be "Male"
…"02"
will now be "Female"
."01"
: Person surveyed did not have a physical challenge."02"
: Person surveyed did have a physical challenge.atu_dirty
data setatu_clean <- atu_cleaner
save(atu_clean, file = "atu_clean.Rda")
View
your data to make sure it looks clean and tidy before saving.