Vishal
Vishal

Reputation: 189

How to create given specific pivot table in R?

I have a requirement of creating pivot table from dataframe given below :

enter image description here

Kindly help me to get pivot table as given below (I have copied from excel) :

enter image description here

I need exactly given as using R.

To generate the similar set of dataset you can use the command given below :

enter code here

Data1 <- data.frame(
X = sample(1:10),
Y = sample(1:10), 
Z = sample(1:10),
count= sample(11:20))

Thanks in advance !

Upvotes: 1

Views: 313

Answers (1)

lukeA
lukeA

Reputation: 54277

Try ftable:

exData <- setNames(as.data.frame(unique(t(combn(rep(1:3, 3), m=3)))), paste0("P", 1:3))
ftable(exData)

Upvotes: 2

Related Questions