5.1 Alfa: a script that works
A fictional script for a dataset of people who went for a swim:
Where did you swim and how hot was it outside?
infile <- "swim.csv"
(dat <- read.csv(infile))
#> name where temp
#> 1 Adam beach 95
#> 2 Bess coast 91
#> 3 Cora seashore 28
#> 4 Dale beach 85
#> 5 Evan seaside 31
- Observations were classified as American or British based on how they described the beach:
dat$english[dat$where == "beach"] <- "US"
dat$english[dat$where == "coast"] <- "US"
dat$english[dat$where == "seashore"] <- "UK"
dat$english[dat$where == "seaside"] <- "UK"
- Temperatures were converted to Celsius:
dat$temp[dat$english == "US"] <- (dat$temp[dat$english == "US"] - 32) * 5/9
dat
#> name where temp english
#> 1 Adam beach 35.0 US
#> 2 Bess coast 32.8 US
#> 3 Cora seashore 28.0 UK
#> 4 Dale beach 29.4 US
#> 5 Evan seaside 31.0 UK
- Data is written back out to a CSV file. A timestamp is also captured in the filename.