Module 9 – Importing & Exporting Data Using dplyr & readr

Module 9 is all about learning the ropes of getting your data into and out of R efficiently. By the end of this module, you will have gained the knowledge to bring data sets into your R environment, wrangle them to suit your needs, and export your results for use in other applications. This is an essential step in your data analysis journey, allowing you to interact with a wide range of data sources and share your insights with ease.

Video Lecture

Exercises

This module does not contain exercises. However, we will work with external data repeatedly during this course, so you will have a lot of practice on importing and exporting data after finishing this course.

Data & R Code of This Lecture

You can find the data set used in this module here (see data attribution below). It includes information on the most popular programming languages spanning from 2004 to 2023. The values for each programming language are presented as percentages, totaling 100%.

# install.packages("tidyverse")                   # Install tidyverse packages
library("tidyverse")                              # Load tidyverse packages
 
my_path <- "D:/Dropbox/Jock/Data Sets/dplyr Course/"  # Specify directory path
 
tib_ppl <- read_csv(str_c(my_path,                # Import CSV file
                          "All-Programming-Languages.csv"))
tib_ppl                                           # Print tibble
 
tib_ppl %>%                                       # Print bottom rows
  slice_tail(n = 5)                               # Apply slice_tail() function
 
tib_ppl %>%                                       # Print entire tibble
  print(n = nrow(tib_ppl))
 
View(tib_ppl)                                     # Show tibble in new window
 
tib_ppl_new <- tib_ppl %>%                        # Problematic column names
  select(Date, C/C++, Java, Julia, Matlab, Python, R, Scala)
 
tib_ppl_new <- tib_ppl %>%                        # Select certain columns
  select("Date", "C/C++", "Java", "Julia", "Matlab", "Python", "R", "Scala")
tib_ppl_new                                       # Print new tibble
 
tib_ppl_new %>%                                   # Export CSV file
  write_csv(str_c(my_path, "My-Programming-Languages.csv"))

Data Attribution

This module includes material from Muhammad Khalid and is licensed under CC BY 4.0 Deed. You can find the source of this data set here. Originally, the data was pulled from here.

Further Resources

 

Move to Previous Module Button

.

Move to Next Module Button

 

You can access the course overview page, timetable, and table of contents by clicking here.

 

Subscribe to the Statistics Globe Newsletter

Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.


Top