Mutate and Transmute PDF

Title Mutate and Transmute
Author Shamraiz Rafeeq
Course R studio
Institution University of Essex
Pages 5
File Size 153.9 KB
File Type PDF
Total Downloads 98
Total Views 150

Summary

Download Mutate and Transmute PDF


Description

Mutate and Transmute The mutate() function adds new variables to the data frame. Multiple new variables can be generated with a single function call, using a comma to separate each new variable. The name of each new variable is specified on the left of the = and a function that can contain names of other variables in the table is specified on the right. The following example converts the minimum and maximum temperature variables from Fahrenheit to Celsius. mutate(mesosm, (TMIN - 32) * .5556)

TMINC = (TMIN - 32) * .5556,

TMAXC =

## # A tibble: 240 x 11## MONTH YEAR STID TMAX TMIN HMAX HMIN RAIN DATE TMINC TMAXC## ## 1 1 2014 BUTL 52.0 21.6 76.3 27.2 0.01 2014-01-01 -5.79 -5.79 ## 2 2 2014 BUTL 47.5 22.3 88.8 41.2 0.26 2014-02-01 -5.41 -5.41 ## 3 3 2014 BUTL 61.1 31.3 79.5 27.1 0.59 2014-03-01 0.409 -0.409## 4 4 2014 BUTL 74.9 45.3 80.2 25.1 1.33 2014-04-01 7.41 7.41 ## 5 5 2014 BUTL 84.8 56.0 79.1 28.4 2.76 2014-05-01 13.4 13.4 ## 6 6 2014 BUTL 89.0 67.1 89.7 42.8 2.97 2014-06-01 19.5 19.5 ## 7 7 2014 BUTL 91.4 67.8 87.2 37.7 3.85 2014-07-01 19.9 19.9 ## 8 8 2014 BUTL 96.5 68.0 82.6 27.9 0.22 2014-08-01 20.0 20.0 ## 9 9 2014 BUTL 85.9 61.2 89.3 39.1 2.39 2014-09-01 16.2 16.2 ## 10 10 2014 BUTL 78.8 48.5 92.3 32.3 2.62 2014-10-01 9.17 9.17 ## # ... with 230 more rows The transmute() function only keeps the newly-created variables. transmute(mesosm, (TMIN - 32) * .5556)

TMINC = (TMIN - 32) * .5556,

TMAXC =

## # A tibble: 240 x 2## TMINC TMAXC## ## 1 5.79 -5.79 ## 2 -5.41 -5.41 ## 3 -0.409 -0.409## 4 7.41 7.41 ## 5 13.4 13.4 ## 6 19.5 19.5 ## 7 19.9 19.9 ## 8 20.0 20.0 ## 9 16.2 16.2 ## 10 9.17 9.17 ## # ... with 230 more rows 3.1.5 Application The following examples will use another meteorological dataset from the Oklahoma Mesonet. The mesodata_large.csv file contains daily data records from every Mesonet station in Oklahoma from 1994-present. This this is a very large data table, more than with more than one million rows and over 150 Mb of data. There are also numerous missing data codes (values < -990 or > 990) that will need to dealt with. mesobig...


Similar Free PDFs