[Solved] how to do a column split and dcast in r [duplicate]


Here is a tidyverse possibility

library(tidyverse)
df %>%
    separate_rows(Weather) %>%
    group_by(Date) %>%
    mutate(n = 1) %>%
    spread(Weather, n, fill = 0)
## A tibble: 6 x 4
## Groups:   Date [6]
#  Date         Fog  Rain Thunderstorm
#  <fct>      <dbl> <dbl>        <dbl>
#1 2018-01-01    1.    1.           0.
#2 2018-01-02    1.    1.           0.
#3 2018-01-03    0.    1.           0.
#4 2018-01-04    0.    0.           1.
#5 2018-01-05    1.    1.           0.
#6 2018-01-06    0.    1.           1.

solved how to do a column split and dcast in r [duplicate]