Stack Exchange
How to create a dataframe with rows of open and close as columns
From this example of dataframe:
dframe <- data.frame(status = c("open","close","open","close"), name = c("Google","Google","Amazon","Amazon"), id = c(1,1,2,2), volume1 = c(2,3,1,2), othercol = c(5.3,1,3,7))

How is it possible to create a new dataframe with columns of open and close as columns? Here an expected output example:
data.frame(name = c("Google", "Amazon"), id = c(1,2), volume1_open = c(2,1), volume1_close = c(3,2), othercol_open = c(5.3,3), othercol_close = c(2,7))


> name id volume1_open volume1_close othercol_open othercol_close
>         Google  1            2             3           5.3              2
>         Amazon  2            1             2           3.0              7


Using data.table, you can use dcast in order to reshape your data to wide format:
Code
setDT(dframe)
dcast(dframe, name + id ~ status, value.var = c('volume1', 'othercol'))

Result
     name id volume1_close volume1_open othercol_close othercol_open
1: Amazon  2             2            1              7           3.0
2: Google  1             3            2              1           5.3

