Transitioning SQL to dplyr by Djoni Darmawikarta

Transitioning SQL to dplyr by Djoni Darmawikarta

Author:Djoni Darmawikarta [Darmawikarta, Djoni]
Language: eng
Format: epub
Published: 2017-03-29T07:00:00+00:00


Renaming Column

In SQL you rename output column (a.k.a. column aliasing) as follows.

SELECT column AS renamed_column, … FROM table;

In dplyr, you use the rename function. In the following example we rename hair to hair.colour.

Renaming more than one column

In the following example, eye is renamed eye.color and n is renamed freq.

Derived Column

In SQL’s SELECT we can have a derived (computed) output column.

SELECT *, n/100 FROM table;

In dplyr we use mutate function to add such a column. In the following example we rename the derived column freq/10 into norm.freq.



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.