CYLINDER AREA
cylinder<-function(r,h){area<-2*pi*r*h+2*pi*r^2
return(area)}
cylinder(2,3)
## [1] 62.83185
cylinder(1:6,12:17)
## [1] 81.68141 188.49556 320.44245 477.52208 659.73446 867.07957
cylinder<-function(r,h){area<-2*pi*r*h+2*pi*r^2
return(c(r,h,area))}
cylinder(2,3)
## [1] 2.00000 3.00000 62.83185
cylinder(1:6,12:17)
## [1] 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 12.00000
## [8] 13.00000 14.00000 15.00000 16.00000 17.00000 81.68141 188.49556
## [15] 320.44245 477.52208 659.73446 867.07957
cylinder<-function(r,h){area<-2*pi*r*h+2*pi*r^2
return(cbind(r,h,area))}
cylinder(2,3)
## r h area
## [1,] 2 3 62.83185
cylinder(1:6,12:17)
## r h area
## [1,] 1 12 81.68141
## [2,] 2 13 188.49556
## [3,] 3 14 320.44245
## [4,] 4 15 477.52208
## [5,] 5 16 659.73446
## [6,] 6 17 867.07957
IFELSE
data(cars)
head(cars)
library(ggplot2)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
cars<-cars%>%mutate(color=ifelse(speed<14,"blue",ifelse(speed>14,"red","black")))
head(cars)
summary(cars)
## speed dist color
## Min. : 4.0 Min. : 2.00 Length:50
## 1st Qu.:12.0 1st Qu.: 26.00 Class :character
## Median :15.0 Median : 36.00 Mode :character
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
GROUP_BY COLOR
ars<-cars%>%mutate(color=ifelse(speed<14,"blue",ifelse(speed>14,"red","black")))%>%group_by(color)%>%count()
ars
SUMMARISE
cars<-cars%>%mutate(color=ifelse(speed<14,"blue",ifelse(speed>14,"red","black")))%>%summarise_at(.vars=vars(speed,dist),.funs = mean)
cars