Statystyka/zajecia1/zajecia1.R

100 lines
1.5 KiB
R
Raw Normal View History

2021-03-11 09:33:49 +01:00
# ZAD1 & ZAD2
x <- c(rep(TRUE, 3), rep(FALSE, 4), rep(TRUE, 2), rep(FALSE, 5))
y <- as.numeric(x)
#ZAD3
z <- c(seq(1, 20, by=1), rep(0, 10), seq(2, 40, by=2))
z <- c(z, rev(z))
print(z)
#ZAD4
print(letters[25])
#ZAD5
zad5 <- 1:1000
for(i in 1:length(zad5)){
if (zad5[i]%%2==0){
zad5[i]=1/zad5[i]
}
}
print(zad5)
#ZAD6
zad6 <- c(6, 3, 4, 5, 2, 3)
print(zad6[order(zad6, decreasing = TRUE)])
#ZAD7
zad7 <- c(-1.876, -1.123, -0.123, 0, 0.123, 1.123, 1.876)
znak <- vector()
zaok <- vector()
calk <- vector()
for (x in zad7){
zaok <- c(zaok, round(x, digits=2))
calk <- c(calk, floor(x))
if (x<0){
znak <- c(znak, -1)
} else if (x>0){
znak <- c(znak, 1)
} else {
znak <- c(znak, 0)
}
}
print(znak)
print(zaok)
print(calk)
#ZAD8
2021-03-11 10:13:43 +01:00
start <- Sys.time()
for (x in 1:100000000){
pierw <- sqrt(x)
}
print(Sys.time() - start)
start <- Sys.time()
for (x in 1:100000000){
pierw <- x^(1/2)
}
print(Sys.time() - start)
#ZAD9
install.packages("schoolmath")
library(schoolmath)
last <- 0
number <- 0
for (x in primlist){
if (x >= 1000){
print(last)
break
}
last <-x
if (x > 100 && x < 500){
number <- number + 1
}
}
print(number)
# ZAD 10
print(c(paste(paste(rep("a", 3), 1:3, sep = "")), paste(paste(rep("b", 3), 1:3, sep = ""))))
#ZAD 11
litery <- c("X", "Y", "Z")
print(paste(1:30, rep(litery, 10), sep="."))
#ZAD 12
install.packages("car")
library(car)
odpowiedzi <- c("a", "b", "c", "d", "e")
x <- sample(odpowiedzi, 100, replace = TRUE)
print(recode(x, "c('a', 'b') = 1; c('c', 'd') = 2; 'e' = 3"))
2021-03-11 09:33:49 +01:00