This Is The Course Script
This Is The Course Script
set.seed(65)
set.seed(65)
set.seed(65)
set.seed(65)
set.seed(65)
# Operators: + - / * ^
x = c(4, 5, 6)
# c for concatenate
x = c(4,5,6)
x # display in console
objects()
# Removing an object
rm("x")
# Working with vectors
x = c(y, 5, y)
x
# Sum and roots
sum(x)
sqrt(x)
## Types of brackets
seq(from = 3, to = 5)
# using length
seq(from = 3, length = 3)
# step manipulations
seq(from = 3, length = 3, by = 0.5)
paste(1:4)
paste("xyz", 1:10)
rep(c(3,4,5), 3)
rep(1:10, times = 3)
x = c(1,2,3) # creating x
x[3]
### Exercise
# 1 . Create the object "myobject" and assign the values 1:10
# in at least 3 different ways
## Solutions
myobject = (1:10)
assign("myobject", 1:10)
sum (myobject)
x[7]
### Functions in R
# we use any to check that i (of this loop round) is still in s, multiples of i
will be removed
if(any(s==i)){
# we store i if it meets our criteria in p together with the previous p
p = c(p,i)
# to search for numbers with a remainder at modulus division
s = c(s[(s%%i) != 0],i)
}}
return(p) }
# to specify the output if n < 2 (optional)
else{
stop("Input at least 2")
}}
PrimVec(100)
?airmiles
summary(mtcars)
hist(airmiles) # histogram
head(mtcars)
sum(mtcars$wt)
mtcars[2,6]
mtcars[c(2,5,8),6]
# simple scatterplot
# color manipulation
colors()
?pch
x=2:4
plot(1:7, ylab="", main="Line Types lty 0:6", xlab="lty 0:6") # test plot
? plot
?par
par()
## Solution
x = 1:141
y = rivers