1 Next steps

Of course, this page provided only a glimpse into the basics of coding with R.

Nevertheless, I am fairly confident that this page is a good basis for all standard data tasks (data management, visualizations, regressions) within ISG and that >80% of all of those tasks are covered by the packages and functions which are on this page.

There are seemingly endless possibilities to go on from here. To provide some orientation, this page lists a couple of (free online) resources (see below).

1.1 If we had a little more time…

If we had an additional day or so, I would have covered the topics in the list below. This list is an indication of what I consider to be “logical” next learning steps. At least the looping architecture is something you should consider learning one day even if you want to stick to the basics of data management, visualizations, and regressions.

  • Loops/Apply Family: This free DataCamp Intro familiarizes you with loops and their alternatives. Loops are about automating a multi-step process by organizing sequences of actions or ‘batch’ processes and by grouping the parts that need to be repeated.

  • Functions: Quick and intuitive overview on how to write your own functions.

  • Shiny: Intro into shiny - learn it from the developers. Shiny is a R package that makes it easy to build interactive web apps straight from R.

2 A glimpse into new stuff

Something which might be of special interest to ISG - word clouds. Credits to Georg, who made this word cloud example based on the ISG staff pages.

library("tidyverse")
library("rvest")
library("tidytext")
## Warning: package 'tidytext' was built under R version 3.5.3
library("SnowballC")
library("wordcloud2")
## Warning: package 'wordcloud2' was built under R version 3.5.3
# get list via https://www.xml-sitemaps.com/
ma <- c("jenny-bennett", 
        "dr-dietrich-engels", 
        "ferzaneh-fakdani", 
        "stefan-feldens", 
        "dr-philipp-fuchs", 
        "katrin-hunger", 
        "lisa-huppertz", 
        "georg-kalvelage", 
        "dr-regine-koeller", 
        "kunze", 
        "christian-loschelder", 
        "vanita-matta", 
        "christine-maur", 
        "uta-micic", 
        "franziska-porwol", 
        "marco-puxi", 
        "eva-roth", 
        "friedrich-scheller", 
        "alina-schmitz", 
        "anne-marie-scholz", 
        "katja-seidel", 
        "hans-verbeek", 
        "juergen-viedenz", 
        "wellmer", 
        "kunze")

# url parameters
base_url <- "https://www.isg-institut.de/autor/"

# scrap profiles  
data <- lapply(ma, function(person) {
  url <- paste0(base_url, person)
  
  html <- read_html(url, verbose = TRUE)
  
  core <- html %>%
    html_nodes(".ma-text p") %>% 
    html_text()
})

# create dataframe
text <- tibble(profil = unlist(data))

# list of stopwords
stopwords_de <- enframe(stopwords::stopwords("de"), name = NULL, value = "words")

# tokenize / remove stopwords and numbers 
token <- text %>%
  filter(profil != "") %>%
  unnest_tokens(input = profil, output = words, to_lower = FALSE) %>%
  filter(str_detect(words, "[A-Z]+")) %>%
  mutate(lower = str_to_lower(words, locale = "de")) %>%
  anti_join(stopwords_de, by = c("lower" = "words"))

# aggregate words / filter freqs
wordcounts <- token %>%
  count(words) %>%
  arrange(desc(n)) %>%
  filter(words != "Seit") %>% # quick fix
  filter(n > 2)

# generate wordcloud
wordcloud2(wordcounts, shuffle = FALSE, color = "blue") 

3 Important Resources

As you cannot emphasize this enough, here again a list of resources to help you in your workflow.

Stackoverflow: A general discussion forum for programmers, including many R users. Just google your question and make sure to place an “R” in the beginning of your question. Most often you will be directed to stackoverflow.

DataCamp: Online tutorials with in-browser coding tasks. Everything beyond beginners levels is behind a paywall. If you want to avoid DataCamp, here is a list of DataCamp tutorials with mostly free alternatives.

Cheat Sheets: Cheat Sheets are a great way to get a concise overview over the functionality and logic of the R topic they cover. to the best of my knowledge, all major packages have one. Some examples

3.1 Individual Trouble Shooting

Learning how to find out about stuff in R by yourself is one of the key techniques for smooth coding.

If you have any questions, one of the following might help:

  • ?functionname (and press enter) to retrieve the official documentation
  • google (make sure to type r somewhere into your query; stackoverflow results are preferable)
  • Ask us ;)

4 (Online) Books

Credits for gathering most of these books go to TheRBootcamp - see this page.

Most but not all of the books are free and online accessible.

Books are ordered by complexity, beginning with user-friendly books on learning statistics in R and ending with books focusing on the more advanced topics of the R language.

W3Schools W3Schools W3Schools W3Schools
W3Schools W3Schools
<td>
W3Schools
W3Schools
W3Schools W3Schools W3Schools W3Schools
W3Schools W3Schools W3Schools W3Schools
W3Schools