Q1
a<-1000 #area of island
b<-30 #trees
c<-7 #drunk
Jacks.Equation <- (a * b) - c * 324 + log(a)
Q2
# i accedentely deleted the fuction data <- c(6, 3, 8, 6, 3, 2, 3, 2, 100)
# standardize.me(data)
# x<-data
# mean(x)
# sd(x)
# standardize.me<-(x-14.77778)/32.02646
Q3 Write a function called how.many that takes two arguments (data and value). The function should return a value indicating how many times the element value occurred in the vector data
how.many<- function(data, value) {
output<- sum (data == value)
return (output)
}
how.many(data = c(1, 1, 9, 3, 2, 1, 1), value = 1)
## [1] 4
data<-c(1, 1, 9, 3, 2, 1, 1)
Q4 Write a function called recode.numeric() with 3 arguments: x, lb, and ub. We’ll assume that x is a numeric vector. The function should look at the values of x, convert any values below lb and above ub to NA, and then return the resulting vector.
vector.x<-c(5, 6, -10, 2, 1000, 2)
lb <- 0
ub <- 100
recode.numeric<- function (vector.x, lb, ub) {
vector.x[vector.x<lb]<- NA
vector.x[vector.x>ub]<- NA
return (vector.x)
}
survey <- data.frame(
id = 1:6,
q1 = c(6, 2, 5, -1, 11, 100),
q2 = c(-5, 4, 65, 3, 7, 6),
q3 = c(2, 1, 2, 45, 5, -5)
)
survey.new <- function (survey, lb, ub) {
survey[survey<lb]<- NA
survey[survey>ub]<- NA
return (survey)
}