We will pass the following variables into melt function:
data set
what columns are IDs
what columns are variables
The following code will add one more column with row names and primarilly, make IDs from "carname", "gear" and "cyl". The remaining columns will be melted down.
Let's have a look at the melted values.
The better way to see what happend is to display values in table. Watch values in variable column.
Casting data sets
We can cast the data set into different shapes.
We can specify function to aggregate values.
Average Values
We will InsectSprays data set.
The following code is using tapply function to show sum of count column for each spray.
Split values
Split and sum
Combine
We can combine the values craeted above in two ways.
Using plyr package to summarize values
Be careful, there is summarise and NOT summarize. If you do that mistake you get argument "by" is missing, with no default error.