Created
September 1, 2022 09:29
-
-
Save hannesdatta/ac7f545fb7fe60e6ed1264458358e176 to your computer and use it in GitHub Desktop.
R scripts written intro class to R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is the R Bootcamp - demo (written by Hannes) | |
1+1 | |
cat("Hello!") | |
name <- 'Hannes' | |
dir.create('data') | |
dir.create('data_output') | |
dir.create('documents') | |
dir.create('fig_output') | |
dir.create('scripts') | |
# data | |
# data_output | |
# documents | |
# fig_output | |
# scripts | |
age <- 20 | |
age = 20 | |
age * 2 | |
age / 2 | |
age == 20 | |
age = 10 | |
" " | |
' ' | |
numbers <- c(1, 2, 3, 10, 20) | |
cities <- c("Berlin", "Barcelona", NA) | |
numbers[5] | |
numbers[numbers>=3] | |
### Exercises | |
# 1 | |
rooms <- c(1,2,1,8) | |
# 2 | |
max(rooms) | |
# 3 | |
rooms <- c(rooms, NA) | |
rooms <- c(1,2,1,8,NA) | |
rooms <- append(rooms, NA) | |
max(rooms, na.rm=T) | |
rooms[3] | |
length(rooms[rooms>=2]) | |
rooms[rooms>=2] | |
length(rooms[which(rooms>=2)]) | |
### | |
download.file("https://raw.githubusercontent.com/hannesdatta/course-dprep/master/content/docs/modules/week4/regional-global-daily-latest.csv", "streams.csv") | |
library(tidyverse) | |
streams <- read_csv('streams.csv', skip=1) | |
streams | |
# Solutions to last exercise | |
streams %>% select(Artist, `Track Name`) | |
streams %>% filter(Artist=='Lil Nas X') | |
streams %>% group_by(Artist) %>% summarize(streams=sum(Streams)) %>% arrange(desc(streams)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment