我基本上想做的是ddply(df, columns.to.preserve, numcolwise(FUNCTION)
的相反。數據幀的逐行擴展
假設我有
d <- data.frame(
count=c(2,1,3),
summed.value=c(50,20,30),
averaged.value=c(35,80,20)
)
count summed.value averaged.value
1 2 50 35
2 1 20 80
3 3 30 20
我想要做的基礎上,count
列同時指定我想申請到其他列什麼樣的操作這個data.frame的一排擴展。 這裏是樣的結果我在尋找:
> d2
count summed.value averaged.value
1 1 25 35
2 1 25 35
3 1 20 80
4 1 10 20
5 1 10 20
6 1 10 20
任何有內置函數內dplyr
或其他包,做這種手術?
編輯:這與De-aggregate/reverse-summarise/expand a dataset in R
問題有所不同,因爲我想進一步實際應用不同的函數到我希望展開的表內的列。這篇文章中還有更多有用的答案。
一些地方開始擴大data.frame [這裏](HTTP ://stackoverflow.com/questions/38208529/de-aggregate-reverse-summarise-expand-a-dataset-in-r)。一旦完成,只需用'count'將'summed.value'和'count'分開。 – aosmith