This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
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(tidyr)
stock_df <- read.csv("stock_df.csv")
stock_df_long <- pivot_longer(stock_df, cols = -company,
names_to = "week",
values_to = "price")
stock_df_long <- stock_df_long %>%
separate(week, into = c("year", "week"), sep = "_week") %>%
mutate(year = as.integer(year), week = as.integer(week))
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `year = as.integer(year)`.
## Caused by warning:
## ! NAs introduced by coercion
print(stock_df_long) %>%
View()
## # A tibble: 525 × 4
## company year week price
## <chr> <int> <int> <dbl>
## 1 Amazon NA 1 1848.
## 2 Amazon NA 2 1641.
## 3 Amazon NA 3 1696.
## 4 Amazon NA 4 1671.
## 5 Amazon NA 5 1626.
## 6 Amazon NA 6 1588.
## 7 Amazon NA 7 1608.
## 8 Amazon NA 8 1632.
## 9 Amazon NA 9 1672.
## 10 Amazon NA 10 1621.
## # ℹ 515 more rows
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.