-
Notifications
You must be signed in to change notification settings - Fork 5
/
L13_DataFrames.Rmd
70 lines (47 loc) · 1.1 KB
/
L13_DataFrames.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
---
title: "Data Frames"
author: "Bert Gollnick"
output:
html_document:
toc: true
toc_float: true
code_folding: hide
number_sections: true
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = T, message = F, warning = F)
```
# Introduction
This tutorial will help you to understand
- how to create a dataframe
- how to access elements in a dataframe
- how to delete columns
## Dataframe Creation
A dataframe is created either by importing data, or from hand.
Nowadays tibbles replace dataframes. They are dataframes, but the print nicer, and somer other small improvements.
```{r}
library(tidyverse)
```
```{r}
wind_oem <- data_frame(name = c("Vestas", "SGRE", "GE"),
market_share = c(16, 15, 10))
wind_oem
```
## Access Elements
You can access columns with $ operator
```{r}
wind_oem$name
```
or with the second argument of [] operator
```{r}
wind_oem[, 1]
```
The same way you can access rows.
```{r}
wind_oem[1, ]
```
## Delete Columns
If you want to delete columns you can assign NULL operator to the column.
```{r}
wind_oem$market_share <- NULL
```