library(tidyverse) my_N <- 100 df <- bind_rows(tibble(ticker = rep('STOCK 1', my_N), ref_date = Sys.Date() + 1:my_N, price = 100 + cumsum(rnorm(my_N))), tibble(ticker = rep('STOCK 2', my_N), ref_date = Sys.Date() + 1:my_N, price = 100 + cumsum(rnorm(my_N))) ) print(df) # convert from long to wide df_wide <- spread(data = df, key = 'ticker', value = 'price') # print result print(df_wide)
# none my_answers <- rep(0, 5)
Change the format of the previous dataframe
, from long to wide or vice versa.
library(tidyverse) my_N <- 100 df <- bind_rows(tibble(ticker = rep('STOCK 1', my_N), ref_date = Sys.Date() + 1:my_N, price = 100 + cumsum(rnorm(my_N))), tibble(ticker = rep('STOCK 2', my_N), ref_date = Sys.Date() + 1:my_N, price = 100 + cumsum(rnorm(my_N))) ) print(df)
extype: string
exsolution: r mchoice2string(c(TRUE, FALSE, FALSE, FALSE, FALSE), single = TRUE)
exname: "function 01"
exshuffle: TRUE
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.