Use Rmarkdown to demonstrate the skills below. Be brief and clear. Provide explanations if necessary to ensure clarity.
Note - I’m not sure where to obtain filename1.R and couldn’t find directions in the syllabus/the project 1 description finding it. For this reason I just created my own filename1.r and filename2.r.
setwd("~/Desktop/repitest/")
source("filename1.R")
## [1] "Successfully source file1name"
#df <- read.table("filename2.dat")
x <- (1:10)
x[3:8] <- "changed"
x
## [1] "1" "2" "changed" "changed" "changed" "changed" "changed"
## [8] "changed" "9" "10"
# convert date
date <- as.Date('April 26, 2001',format='%B %d, %Y')
# then get day of date
weekdays(date)
## [1] "Thursday"
x <- 1:10
sumx <- sum(x)
library(testthat)
test_that("Correct mode", {
sumx <- sum(x)
expect_that( sumx, is_a("integer") )
})
# Multiply even elements by 10
x <- (1:10)
for (i in seq_along(x)) {
if (i%%2 == 0){
x[i] <- i * 10
}
}
x
## [1] 1 20 3 40 5 60 7 80 9 100
who_is_the_coolest_professor <- function() {return("Tomas Aragon")}
df2 <- data.frame(x=1:10,y=sample(100,10))
png(filename="~/Desktop/repitest/imageforproject1.png")
plot(df2$x, df2$y, xlab="x values",ylab="y values", main="Simple plot", 'l', col='tomato', lwd=15)
dev.off()
## quartz_off_screen
## 2
grep("a+", c("abc", "def", "cba a", "aa"), perl=TRUE, value=TRUE)
## [1] "abc" "cba a" "aa"
#sink('~/Desktop/repitest/') # open connection
cat('Here are results of sumx function', fill = TRUE)
## Here are results of sumx function
show(sumx)
## [1] 55
#sink() # close connection