| Start | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Pivot and unpivot tabular data with data.table - I Convert from wide form to long form Load Use This is data in the wide form. It has a column for each variable. The data can also be stored in long form without loss of information. The long form has one column that stores the variable names. Then, it has another column for the variable values. The long form of We use the By default, Note that we have specified the names of the column containing category names (Murder, Assault, etc.) with Generating summaries with with split-apply-combine style approach is a breeze. For example, to summarize violent crimes by state? This gives: |
||||||||||||||
| Pivot and unpivot tabular data with data.table - II Convert from long form to wide form To recover data from the previous example, use This gives the data in the original wide form. Here, the formula notation is used to specify the columns that form a unique record identifier (LHS) and the column containing category labels for new column names (RHS). Which column to use for the numeric values? By default, When the operation produces a list of values in each cell, Now, casting This gives: This gives: There are multiple states in each decile of the urban population. Use This sums over the data for like states, giving the following. Syntax
Parameters
RemarksMuch of what goes into conditioning data to build models or visualizations can be accomplished with |
Read Article
https://develop.horje.com/learn/1434/reference