Grain y ields and u nit con v ersion IN TR OD U C TION TO W R ITIN G FU N C TION S IN R Richie Co � on C u rric u l u m Architect at DataCamp
USDA NASS INTRODUCTION TO WRITING FUNCTIONS IN R
Corn and w heat Soon these w ill be food Hmm , delicio u s INTRODUCTION TO WRITING FUNCTIONS IN R
1 acre = area of land 2 o x en can plo u gh in a da y INTRODUCTION TO WRITING FUNCTIONS IN R
Not the 100 Acre Wood INTRODUCTION TO WRITING FUNCTIONS IN R
1 hectare = 2 football fields INTRODUCTION TO WRITING FUNCTIONS IN R
1 hectare = 150 Ne w York apartments INTRODUCTION TO WRITING FUNCTIONS IN R
1 b u shel = 2 baskets of peaches INTRODUCTION TO WRITING FUNCTIONS IN R
1 kilogram = 1 sq u irrel monke y INTRODUCTION TO WRITING FUNCTIONS IN R
magrittr ' s pipeable operator replacements operator f u nctional alternati v e x * y x %>% multiply_by(y) x ^ y x %>% raise_to_power(y) x[y] x %>% extract(y) INTRODUCTION TO WRITING FUNCTIONS IN R
Let ' s practice ! IN TR OD U C TION TO W R ITIN G FU N C TION S IN R
Vis u ali z ing grain y ields IN TR OD U C TION TO W R ITIN G FU N C TION S IN R Richie Co � on C u rric u l u m Architect at DataCamp
The corn dataset glimpse(corn) Observations: 6,381 Variables: 6 $ year <int> 1866, 1866, 1866, 1866, 1866, 1866... $ state <chr> "Alabama", "Arkansas", "California... $ farmed_area_acres <dbl> 1050000, 280000, 42000, 57000, 200... $ yield_bushels_per_acre <dbl> 9.0, 18.0, 28.0, 34.0, 23.0, 9.0, ... $ farmed_area_ha <dbl> 424919.92, 113311.98, 16996.80, 23... $ yield_kg_per_ha <dbl> 79.29892, 158.59784, 246.70776, 29... INTRODUCTION TO WRITING FUNCTIONS IN R
ggplot 2: dra w ing m u ltiple lines ggplot(dataset, aes(x, y)) + geom_line(aes(group = group)) INTRODUCTION TO WRITING FUNCTIONS IN R
ggplot 2: smooth trends ggplot(dataset, aes(x, y)) + geom_line(aes(group = group)) + geom_smooth() INTRODUCTION TO WRITING FUNCTIONS IN R
ggplot 2: facetting ggplot(dataset, aes(x, y)) + geom_line(aes(group = group)) + geom_smooth() + facet_wrap(vars(facet)) INTRODUCTION TO WRITING FUNCTIONS IN R
USA Cens u s regions INTRODUCTION TO WRITING FUNCTIONS IN R
dpl y r inner joins dataset1 %>% inner_join(dataset2, by = "column_to_join_on") INTRODUCTION TO WRITING FUNCTIONS IN R
Let ' s practice ! IN TR OD U C TION TO W R ITIN G FU N C TION S IN R
Modeling grain y ields IN TR OD U C TION TO W R ITIN G FU N C TION S IN R Richie Co � on C u rric u l u m Architect at DataCamp
INTRODUCTION TO WRITING FUNCTIONS IN R
Linear models v s . generali z ed additi v e models A linear model A generali z ed additi v e model library(mgcv) lm( gam( response_var ~ explanatory_var1 + explanatory_var2, response_var ~ s(explanatory_var1) + explanatory_var2, data = dataset data = dataset ) ) INTRODUCTION TO WRITING FUNCTIONS IN R
Predicting GAMs predict_this <- data.frame( explanatory_var1 = c("some", "values"), explanatory_var2 = c("more", "values") ) predicted_responses <- predict(model, predict_this, type = "response") predict_this %>% mutate(predicted_responses = predicted_responses) INTRODUCTION TO WRITING FUNCTIONS IN R
Let ' s practice ! IN TR OD U C TION TO W R ITIN G FU N C TION S IN R
Congrat u lations IN TR OD U C TION TO W R ITIN G FU N C TION S IN R Richie Co � on C u rric u l u m Architect at DataCamp
In Chapter 1 y o u learned Writing y o u r o w n f u nctions lets y o u re u se code . There is a simple process for t u rning scripts into f u nctions . Data arg u ments come before detail arg u ments . INTRODUCTION TO WRITING FUNCTIONS IN R
In Chapter 2 y o u learned Defa u lts can be set u sing name = value s y nta x. Arg u ments can be passed bet w een f u nctions u sing their name or ... . Checking u ser inp u ts can be done u sing assertive . INTRODUCTION TO WRITING FUNCTIONS IN R
In Chapter 3 y o u learned Yo u can ret u rn earl y from a f u nction u sing return() . Yo u can pre v ent ret u rn v al u es being printed w ith invisible() . F u nctions can ret u rn m u ltiple v al u es u sing lists or a � rib u tes . R has r u les abo u t scope that determine w hich v ariables can be seen . INTRODUCTION TO WRITING FUNCTIONS IN R
In Chapter 4 y o u learned Writing y o u r o w n f u nctions can be u sef u l for y o u r data anal y ses . E v en simple , one - line f u nctions can be helpf u l . INTRODUCTION TO WRITING FUNCTIONS IN R
More modeling INTRODUCTION TO WRITING FUNCTIONS IN R
Tid y ing models INTRODUCTION TO WRITING FUNCTIONS IN R
Unit testing INTRODUCTION TO WRITING FUNCTIONS IN R
En v ironments Object - Oriented Programming w ith S 3 and R 6 in R INTRODUCTION TO WRITING FUNCTIONS IN R
Thanks for taking the co u rse ! IN TR OD U C TION TO W R ITIN G FU N C TION S IN R
Recommend
More recommend