ID<-c(2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021,2022,2023)
type<-c('Spices','Spices','Fruit','Fruit','Fruit','Spices','Spices','Spices','Spices','Spices','Fruit','Fruit','Spices','Fruit','Fruit','Fruit','Fruit','Spices','Fruit','Fruit')
state<-c('New Jersey','New Jersey','New Jersey','New Jersey','New Jersey','New Jersey','Florida','Michigan','Michigan','New Jersey','New Jersey','New Jersey','New Jersey','New Jersey','New Jersey','Florida','Michigan', 'Michigan','Florida','Florida')
price<-c (1442,639,71,22,1185,508,434,24,528,8,41,82,2994,385,545,1850,2966,31,536,42)
data=data.frame(ID,type,state,price)
library(reshape)
data.m=melt(data, id=c(1:4), measure=c(4))
df1 <-cast(data.m, ID~type+value, sum)
#for adding grand total
df2<- cast(data.m, ID~type+value, sum, margins=c("grand_row"))
#for adding filter
df3 <- cast(data.m, ID~type+value, sum, margins=c("grand_row"),subset=state=="Florida")
DF1、DF2およびDF3はピボットあるお役に立てば幸いです。
rpivotTableは、JavaScriptを使用してブラウザでピボットテーブルをレンダリングします。私のユーザーはデータを含むExcelワークブックをダウンロードしたいと思っています。 –
こんにちは私はそれが役立つかどうかを確認してください別の答えを掲載しました。 – Yogesh