Create a matrix of dummy variables from my data frame; use `NA` for missing values
问题 I have a data based on different years, repeated several time. I want my output having columns equal to number of years, each column for one year. Now, the purpose is to create dummy for each year separately. For example, the output column for year 2000 must have a value "1" whenever there is a non-NA observation in the main data parallel to year 2000, else "0". Moreover, NA must remain NA. Please see below a small sample of input data: df: 2000 NA 2001 NA 2002 -1.3 2000 1.1 2001 0 2002 NA