Some examples from Chapter 5
Teams %>% select(15:40) %>%
apply(MARGIN = 2, FUN = mean, na.rm = TRUE)
R AB H X2B X3B HR BB SO
682.3992945 5146.4733686 1346.9393298 228.1276896 46.9135802 102.0451499 473.9590829 744.1528545
SB CS HBP SF RA ER ERA CG
111.9628391 48.5323887 56.0333333 44.4294118 682.3992945 571.9523810 3.8188783 49.9760141
SHO SV IPouts HA HRA BBA SOA E
9.6592593 23.8673721 4025.6451499 1346.7516755 102.0451499 474.3167549 737.2416226 185.3654321
DP FP
140.2374901 0.9654473
angles_names
[1] "Los Angeles Angels" "California Angels" "Anaheim Angels"
[4] "Los Angeles Angels of Anaheim"
lapply(angles_names, FUN = nchar)
[[1]]
[1] 18
[[2]]
[1] 17
[[3]]
[1] 14
[[4]]
[1] 29
sapply(angles_names, FUN = nchar)
Los Angeles Angels California Angels Anaheim Angels
18 17 14
Los Angeles Angels of Anaheim
29
angles_list
[[1]]
[[2]]
[[3]]
[[4]]
NA
OrdwayBirds %>% select(Timestamp, Year, Month, Day) %>%
glimpse()
Observations: 15,829
Variables: 4
$ Timestamp <chr> "4/14/2010 13:20:56", "", "5/13/2010 16:00:30", "5/13/2010 16:02:15", "5/13/2010 16:03:...
$ Year <chr> "1972", "", "1972", "1972", "1972", "1972", "1972", "1972", "1972", "1972", "1972", "19...
$ Month <chr> "7", "", "7", "7", "7", "7", "7", "7", "7", "7", "7", "7", "7", "7", "7", "7", "7", "7"...
$ Day <chr> "16", "", "16", "16", "16", "16", "16", "16", "16", "16", "17", "18", "18", "18", "18",...
covert to numbers
OrdwayBirds %>% select(Timestamp, Year, Month, Day) %>%
glimpse()
Observations: 15,829
Variables: 4
$ Timestamp <chr> "4/14/2010 13:20:56", "", "5/13/2010 16:00:30", "5/13/2010 16:02:15", "5/13/2010 16:03:...
$ Year <dbl> 1972, NA, 1972, 1972, 1972, 1972, 1972, 1972, 1972, 1972, 1972, 1972, 1972, 1972, 1972,...
$ Month <dbl> 7, NA, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,...
$ Day <dbl> 16, NA, 16, 16, 16, 16, 16, 16, 16, 16, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 20,...
convert Timestamp
WhenAndWho <- OrdwayBirds %>%
mutate(When = mdy_hms(Timestamp)) %>%
select(Timestamp, Year, Month, Day, When, DataEntryPerson) %>%
glimpse()
Observations: 15,829
Variables: 6
$ Timestamp <chr> "4/14/2010 13:20:56", "", "5/13/2010 16:00:30", "5/13/2010 16:02:15", "5/13/2010...
$ Year <dbl> 1972, NA, 1972, 1972, 1972, 1972, 1972, 1972, 1972, 1972, 1972, 1972, 1972, 1972...
$ Month <dbl> 7, NA, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7...
$ Day <dbl> 16, NA, 16, 16, 16, 16, 16, 16, 16, 16, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, ...
$ When <dttm> 2010-04-14 13:20:56, NA, 2010-05-13 16:00:30, 2010-05-13 16:02:15, 2010-05-13 1...
$ DataEntryPerson <chr> "Jerald Dosch", "Caitlin Baker", "Caitlin Baker", "Caitlin Baker", "Caitlin Bake...
now()
as.Date(now())
today()
as.Date(today())
as.Date(now()) - as.Date(today())
How many days have you woken up in the morning? Change the date.
as.Date(today()) - as.Date("01/01/1970")