Advanced R by Matt Wiley & Joshua F. Wiley

Advanced R by Matt Wiley & Joshua F. Wiley

Author:Matt Wiley & Joshua F. Wiley
Language: eng
Format: epub
Publisher: Apress, Berkeley, CA


While melt() is used to make wide data long, dcast() is used to make long data wide. Without unique identifiers for data, multiple values must be aggregated to fit in one cell. Thus, calling our casting function without some thought may create unwanted results (although sometimes aggregating multiple values is exactly what is desired). Notice that in the second formal, Species is called out as the identity key, and variable is named as the location to find our new column names:

dcast(diris.long2, Species ∼ variable)

Aggregate function missing, defaulting to 'length'

Species Sepal.Length Sepal.Width Petal.Length Petal.Width

1: setosa 50 50 50 50

2: versicolor 50 50 50 50

3: virginica 50 50 50 50



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.