Quotes help make search much faster. Example: "Practice Makes Perfect"

Wednesday, September 4, 2019

Codecademy Learn R Rename Columns 5/6


#Sample Solution
---
title: "Modifying Data Frames in R"
output: html_notebook
---

```{r message=FALSE, warning=FALSE}
# load libraries
library(readr)
library(dplyr)
```

```{r message=FALSE}
# load data frame
dogs <- read_csv('dogs.csv')
```

```{r message=FALSE}
# add columns and remove existing columns
dogs <- dogs %>%
  transmute(breed = breed,
            avg_height = (height_low_inches + height_high_inches)/2,
         avg_weight = (weight_low_lbs + weight_high_lbs)/2,
        rank_change_13_to_16 = rank_2016 - rank_2013)
```

```{r}
# check column names
original_col_names <- colnames(dogs)
print(original_col_names)
```

```{r}
# rename data frame columns
dogs <- dogs %>%
rename(avg_height_inches = avg_height, avg_weight_lbs = avg_weight, popularity_change_13_to_16 = rank_change_13_to_16)
```

```{r}
# check column names
new_col_names <- colnames(dogs)
print(new_col_names)
```

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts