Day 3 prepparation
#import libary
library(ggplot2)
library(stringr)
library(rvest)
## Loading required package: xml2
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
calculateRectangle <- function(x,y) {
# check if input is number
if(is.numeric(x) &&is.numeric(y)){
return(x*y)
}else{
return (0);
}
# Return resultl:
}
calculateRectangle(3,2)
## [1] 6
electrice report
#calculate Old Price
calculatePriceOld <- function(x) {
multiplier <- 1549;
if( 50 < x && x < 101 ){
multiplier <- 1600;
}
else if( 100 < x && x < 201){
multiplier <- 1858;
}
else if( 200 < x && x < 301){
multiplier <- 2340;
}
else if( 300 < x && x < 401){
multiplier <- 2615;
}
else if( 400 < x){
multiplier <- 2701;
}
return (multiplier*x)
# Return resultl:
}
calculatePriceNew <- function(x) {
multiplier <- 1549;
if( 100 < x && x < 201){
multiplier <- 1858;
}
else if( 200 < x && x < 301){
multiplier <- 2340;
}
else if( 300 < x && x < 401){
multiplier <- 2701;
}
else if( 400 < x){
multiplier <- 3105;
}
return (multiplier*x)
# Return resultl:
}
calculatePriceOld(10000)
## [1] 27010000
calculatePriceNew(450)
## [1] 1397250
x = seq(500,10000,500)
Old= data.frame(x)
colnames(Old) = c("Consume")
head(Old)
## Consume
## 1 500
## 2 1000
## 3 1500
## 4 2000
## 5 2500
## 6 3000
Old <- Old %>% mutate(PriceOld = calculatePriceOld(Consume),PriceNew = calculatePriceNew(Consume) )
## Warning: Problem with `mutate()` input `PriceOld`.
## i the condition has length > 1 and only the first element will be used
## i Input `PriceOld` is `calculatePriceOld(Consume)`.
## Warning in if (400 < x) {: the condition has length > 1 and only the first
## element will be used
## Warning: Problem with `mutate()` input `PriceNew`.
## i the condition has length > 1 and only the first element will be used
## i Input `PriceNew` is `calculatePriceNew(Consume)`.
## Warning in if (400 < x) {: the condition has length > 1 and only the first
## element will be used
ggplot(Old, aes(Consume)) +
geom_line(aes(y = PriceOld, colour = "old")) +
geom_line(aes(y = PriceNew, colour = "new"))
