In R, I have a time series ts_big in long format as shown below, with observations of type A and B:
ts1<-tibble(dates=c("2023-01-01","2023-02-01","2023-03-01",
"2023-04-01"),
numbers_1=c(1.0, 2.8, 2.9, 2.0),
numbers_2=c(3.0, 5.0, 7.9, 0.9),
types=replicate(4, "A"))
ts2<-tibble(dates=c("2023-01-01","2023-02-01"),
numbers_1=c(0.3, 0.9),
numbers_2=c(3.0, 5.0),
types=replicate(2, "B"))
ts_big<-rbind(ts1, ts2)
Type A has observations at 4 times ("2023-01-01","2023-02-01","2023-03-01"), while type B has observations at only 2 of those same times ("2023-01-01","2023-02-01"). Is there a way to transform this tibble ts_big into a wide format with 5 columns: one single date column one column for type A numbers_1, one column for type A numbers_2, and one column for type B numbers_1, and one column for type B numbers_2 (perhaps with NA values in rows where type B doesn't have observation values for given dates)?
I understand this could be done manually by creating a bunch of vectors then compiling them into a tibble/dataframe but I was wondering if there was a function or simple process that could be used on much larger/complex examples than the small scale one I provided here.
Note: This is an reposted version of a previous post which was I improperly phrased.