![]() |
VOOZH | about |
Syntax: melt(data, na.rm = FALSE, value.name = "value") Parameters: data: represents dataset that has to be reshaped na.rm: if TRUE, removes NA values from dataset value.name: represents name of variable used to store valuesExample: Output:
Original data frame: n time x y 1 1 1 6 1 2 1 2 3 4 3 2 1 2 6 4 2 2 5 9 After melting data frame: n time variable value 1 1 1 x 6 2 1 2 x 3 3 2 1 x 2 4 2 2 x 5 5 1 1 y 1 6 1 2 y 4 7 2 1 y 6 8 2 2 y 9
Casting in R programming is used to reshape the molten data using cast() function which takes aggregate function and formula to aggregate the data accordingly. This function is used to convert long format data back into some aggregated form of data based on the formula in the cast() function.
Syntax: cast(data, formula, fun.aggregate) Parameters: data: represents dataset formula: represents the form in which data has to be reshaped fun.aggregate: represents aggregate functionExample:
Output:
n x y 1 1 9 5 2 2 7 15 time x y 1 1 4 3.5 2 2 4 6.5