Мой исходный фрейм данных, df2
:
df2 <- data.frame(ID = c("1100455", "1100455", "1100455", "1100455", "1100455", "1100464", "1100464"),
CATEGORIE = c("10110", "10160", "10604", "11220", "10110", "10110","10140"),
RANK = c("1", "1", "1", "1", "0" ,"1", "1"),
MD = c("0", "0", "0", "3", "4", "0", "0" ),
PROD3 = c(2345.00,1114.58,501.40,0.00,0.00,2720.00,636.80),
VALUE3 = c(540.00,0.00,0.00,0.00,0.00,0.00,0.00),
AREA3 = c(563.76,0.00,17.35,0.00,0.00,0.00,0.00),
LONG3 = c(4100,2100,1740,265,0,3978,940)
)
Я запускаю эту команду, чтобы распространять некоторые столбцы новостей со значением в соответствии с PROD3 и именем в соответствии с MD, это прекрасно работает, но я теряю все остальные строка:
df3 <- df2 %>%
filter(CATEGORIE == "10110") %>%
mutate(name = str_c("aaaa", MD, "aaa", sep = "_"),
value = PROD3) %>%
spread(name, value)
df3
Как сохранить все строки df2
в df3
?