Dataframe creation

There are two packages you can use in this instance that are superior to the base package, dplyr and tibble. Tibble is faster and easier, so this one will be used for these exercises.

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tibble)

It is important to remember when creating dataframes, that the number of elements within each column need to align to maintain a rectangular format, otherwise the object cannot be created. This is more important if merging datasets together into one frame.

wind_oem <- tibble(name = c("Vestas", "SGRE", "GE"),
                   maraket_share = c(15, 20 , 10)
                   )
wind_oem
## # A tibble: 3 × 2
##   name   maraket_share
##   <chr>          <dbl>
## 1 Vestas            15
## 2 SGRE              20
## 3 GE                10

Acccessing columns within dataframe

wind_oem$name #this will call the column based on its header
## [1] "Vestas" "SGRE"   "GE"
wind_oem[ , 1] #this calls the first column, and includes all rows
## # A tibble: 3 × 1
##   name  
##   <chr> 
## 1 Vestas
## 2 SGRE  
## 3 GE
wind_oem["name"] #this does the same thing, but is similar to how it would look in Pyhton
## # A tibble: 3 × 1
##   name  
##   <chr> 
## 1 Vestas
## 2 SGRE  
## 3 GE
wind_oem[1,] #this calls the first row
## # A tibble: 1 × 2
##   name   maraket_share
##   <chr>          <dbl>
## 1 Vestas            15

To delete a column

wind_oem$maraket_share <- NULL
wind_oem
## # A tibble: 3 × 1
##   name  
##   <chr> 
## 1 Vestas
## 2 SGRE  
## 3 GE