1

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 !

Vishal
  • 179
  • 3
  • 11

1 Answers1

2

Try ftable:

exData <- setNames(as.data.frame(unique(t(combn(rep(1:3, 3), m=3)))), paste0("P", 1:3))
ftable(exData)
lukeA
  • 50,755
  • 5
  • 83
  • 91
  • Thanks Luke, i can able to create the pivot table using ftable function, though i didn't understand the logic used in while saving dataframe in exData. can you please explain the same? Thanks in Advance ! – Vishal Feb 25 '14 at 10:56
  • Can you expand your answer by elaborating each step? – Roman Luštrik Feb 25 '14 at 12:53