Shadow

Tag: Tidyverse

Renaming Columns with R

Renaming Columns with R

Recent Posts, Blog, Data Science
Often data you’re working with has abstract column names, such as (x1, x2, x3…). Typically, the first step I take when renaming columns with r is opening my web browser.  For some reason no matter the amount of times doing this it’s just one of those things. (Hoping that writing about it will change that) The dataset cars is data from the 1920s on "Speed and Stopping Distances of Cars". There is only 2 columns shown below. colnames(datasets::cars) [1] "speed" "dist" If we wanted to rename the column "dist" to make it easier to know what the data is/means we can do so in a few different ways. Using dplyr: cars %>% rename("Stopping Distance (ft)" = dist) %>% colnames() [1] "speed" "Stopping Distance (ft)" cars %>% rename("Stopping Di
Creating Excel Workbooks with multiple sheets in R

Creating Excel Workbooks with multiple sheets in R

Data Science, Recent Posts
Creating Excel Workbooks Generally, when doing anything in R I typically work with .csv files, their fast and straightforward to use. However, I find times, where I need to create a bunch of them to output and having to go and open each one individually, can be a pain for anyone. In this case, it's much better to create a workbook where each of the .csv files you would have created will now be a separate sheet. Below is a simple script I use frequently that gets the job done. Also included is the initial process of creating dummy data to outline the process. EXAMPLE CODE: Libraries used library(tidyverse) library(openxlsx) Creating example files to work with products <- c("Monitor", "Laptop", "Keyboards", "Mice") Stock <- c(20,10,25,50) Computer_Supplies <- ...