Zum Inhalt springen

R Video Tutorial #5: A quick introduction to the pipe

  • von

In this tutorial I give you a quick introduction to the pipe. The pipe has a lot of advantages but here I simply talk about how it works and why your code gets more organised because of it

Here is the link to the datacamp article about the pipe: https://www.datacamp.com/community/tutorials/pipe-r-tutorial

The video:

PS. I made a small mistake in the video. You actually need the data.table package to read in the data with fread. But everything according to the pipe still makes sense.

The code:

setwd("YOURPATHTOYOURWORKINGDIRECTORY")

library(tidyverse)

data <- fread("batting_players_2018.csv")
data <- as_tibble(data)

#Let's filter out the Leauge Average
filter(data, Name != "League Average per 600 PA")

#unique Teams without the pipe
unique(data$Tm)

#average age with the pipe
data$Tm %>% unique()

#filter for the American League
  data %>% filter(Lg == "AL") %>%
  #select Name, Tm, AB, H, BA columsn
  select(Name, Tm, AB, H, BA) %>%
  #calculate BA again
  mutate(avg = H / AB) %>%
  #select second and third column with the . operator
  .[,2:3]

#how the code would look without the pipe
mutate(select(filter(data, Lg == "AL"), Name, Tm, AB, H, BA), 
       avg = H / AB)[, 2:3]

Multivariate Analysen sind aus de Marktforschung nicht mehr wegzudenken. Dabei untersuchen wir die Zusammenhänge und Strukturen mehrerer Variablen und finden so Erkenntnisse, die wertvoll sein können. Von der klassischen Regression bis hin zu neueren Methoden wie der Latent Class Analysis für Segmentierungen, kann ich Ihnen hier ein breites Spektrum an Analysen anbieten. Hier ein Auszug:

Schlagwörter:

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

%d Bloggern gefällt das: