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

Wednesday, September 4, 2019

Codecademy Learn R Splitting By Index 6/10


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

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

```{r}
# load students data frame
load("students.Rda")
```

```{r}
# print columns of students
print(colnames(students))
```

```{r}
# view head of students
head(students)
```

```{r}
# add gender and age columns
students <- students %>%
  mutate(gender = str_sub(gender_age,1,1),
         age = str_sub(gender_age,2))
head(students)
```

```{r}
# drop gender_age column
students <- students %>%
  select(-gender_age)
head(students)
```

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts