I have a dataframe that looks like the following:
Date | Value | Company |
---|---|---|
1/2/13 | 10 | Company1 |
1/2/14 | 20 | Company2 |
1/2/15 | 30 | Company1 |
1/2/16 | 40 | Company3 |
1/2/17 | 50 | Company2 |
1/2/18 | 60 | Company3 |
I would like to subset this dataframe to create 3 different dataframes (one for each unique company). I have been using
assets <- unique(df$Company)
length(assets)
asset1 <- df %>% filter(Company == assets[1])
asset2 <- df %>% filter(Company == assets[2])
asset3 <- df %>% filter(Company == assets[3])
but this gets time consuming if there are 50+ assets.
I was wondering if there was a function in dplyr
or base packages that can create the dataframes in a more efficient manner.
Thank you for your help.
EDIT:
I have tried to create a time series plot using
by_asset <- df %>% group_by(Company)
plots = ggplot(data = by_asset) + aes(x = Date, y = Value) +
geom_point()
but plot returns blank.