This is a practice activity, mean to be completed individually. Please review the activities and attempt them on your own, without relying on the solutions below, or AI support.
You will need to load the general libraries we have used up until this point: 1. dplyr 2. tidyr
AND
Ensure your working directory has been pointed to the correct
location.
Assign objects to all these data frames below.
Code and responses are viewable if you scroll down.
Enough math! Let’s move on…
#setwd("~/Directories/Practice Directory") ### set to your appropriate directory
library(readr)
library(tidyr)
library(dplyr)
cm2<- read_csv("cm2.csv")
dems <- read_csv("dems.csv")
active<- read_csv("active.1yr.csv")
acs<- read_csv("acs.IG.csv")
1234/10.46
## [1] 117.9732
log(117.9732) ### log() is one of many arithmetic functions in base R
## [1] 4.770457
x<- sqrt(608998.91) ## do this in one command for efficiency, versus finding the square root and then manually writing it into the next command
round(x, digits = 2) ## use round() to round a value, and set exactly the amount of spaces
## [1] 780.38
class(cm2$EarningsAmount) ## check the class; if its good to go, no changes needed
## [1] "numeric"
max(cm2$EarningsAmount, na.rm=TRUE)
## [1] 7200
min(cm2$EarningsAmount, na.rm=TRUE)
## [1] 0
mean(cm2$EarningsAmount,na.rm=TRUE)
## [1] 1172.132
class(cm2)
## [1] "spec_tbl_df" "tbl_df" "tbl" "data.frame"
nrow(active)
## [1] 831
str(cm2)## Note we could use summary(), but str() lists the variables so its easier to view
df_1<- active[-c(6, 8, 9:11), c(1:3,5)]
dim(df_1)
## [1] 826 4
8.Using the dpylr package, look at the following columns in cm2: Program Name, Income Adequacy and Income Adequacy Rent. Copy and paste the first 3 rows you see.
cm2 |> select(ProgramName, IncomeAdequacy, IncomeAdequacyRent)
## # A tibble: 397 × 3
## ProgramName IncomeAdequacy IncomeAdequacyRent
## <chr> <chr> <chr>
## 1 Caminos Income is Sufficient and Well-Managed; Has … Spends about 30% …
## 2 Journeys Can Meet Basic Needs with Subsidy; Appropri… <NA>
## 3 Revive Can Meet Basic Needs with Subsidy; Appropri… <NA>
## 4 Revive Can Meet Basic Needs with Subsidy; Appropri… <NA>
## 5 Revive No Income; No Benefits; No Subsidies <NA>
## 6 New Horizons No Income; No Benefits; No Subsidies <NA>
## 7 SH Home Can Meet Basic Needs with Subsidy; Appropri… <NA>
## 8 Healthy Paths Inadequate Income and/or Spontaneous or Ina… <NA>
## 9 Casa Alma No Income; No Benefits; No Subsidies <NA>
## 10 Casa Alma Can Meet Basic Needs with Subsidy; Appropri… <NA>
## # ℹ 387 more rows
names(dems)
## [1] "ParticipantID" "DateOfBirth"
## [3] "ChartNumberACAC" "EnglishFluencyReading"
## [5] "EnglishFluencySpoken" "EnglishFluencyWritten"
## [7] "Ethnicity" "EthnicitySpecify"
## [9] "Latino" "Gender"
## [11] "GenderIDSpecify" "AssignedSex"
## [13] "GenderSpecify" "SexualOrientation"
## [15] "OrientationSpecify" "MaritalStatus"
## [17] "Veteran" "VeteranService"
## [19] "ActiveCombat" "Language"
## [21] "LanguageSpecify" "BirthCity"
## [23] "BirthState" "BirthCountry"
## [25] "FosterCareCounty" "Staff"
## [27] "Address" "Address2"
## [29] "Zip" "Email"
## [31] "Cell Phone" "Work Phone"
## [33] "Work Phone Extension" "ONESystemID"
## [35] "Suffix" "Preferred Name(s)"
## [37] "Pronouns" "Mother's Maiden Name"
## [39] "Alert" "Home Phone"
## [41] "Type of Residence" "Referring Agency (Routz)"
## [43] "Referred from HIV Test Provider?" "Chart Number"
## [45] "Phonetic Spelling"
df_2<- dems |> select(ParticipantID:EnglishFluencyReading, EthnicitySpecify, GenderIDSpecify,FosterCareCounty)