Tukaj pišem tekst, komentarje, naslove….
podatki <- data.frame("ID" = c(1, 2, 3, 4),
"Noga" = c(36, 37, 40, 43),
"Starost" = c(25, 26, 19, 22),
"Spol" = c("Z", "Z", "M", "M"))
print(podatki)
## ID Noga Starost Spol
## 1 1 36 25 Z
## 2 2 37 26 Z
## 3 3 40 19 M
## 4 4 43 22 M
Rad bi naredil novo tabelo s podatki, ki vsebuje samo ID, Starost in Spol.
podatki2 <- podatki[ , -2 ]
print(podatki2)
## ID Starost Spol
## 1 1 25 Z
## 2 2 26 Z
## 3 3 19 M
## 4 4 22 M
Rad bi naredil novo tabelo s podatki, ki vključuje samo 1. in 3. študenta.
podatki3 <- podatki[ c(-2, -4) , ] #Izključimo 2 in 4 enoto
podatki3 <- podatki[ c(1, 3) , ] #Vključimo 1 in 3 enoto
print(podatki3)
## ID Noga Starost Spol
## 1 1 36 25 Z
## 3 3 40 19 M
podatki[1, 2] <- 38
print(podatki)
## ID Noga Starost Spol
## 1 1 38 25 Z
## 2 2 37 26 Z
## 3 3 40 19 M
## 4 4 43 22 M
podatki$Visina <- c(160, 164, 175.3, 179)
print(podatki)
## ID Noga Starost Spol Visina
## 1 1 38 25 Z 160.0
## 2 2 37 26 Z 164.0
## 3 3 40 19 M 175.3
## 4 4 43 22 M 179.0
podatki$Starost1 <- podatki$Starost + 1
print(podatki)
## ID Noga Starost Spol Visina Starost1
## 1 1 38 25 Z 160.0 26
## 2 2 37 26 Z 164.0 27
## 3 3 40 19 M 175.3 20
## 4 4 43 22 M 179.0 23
summary(podatki[ , c(-1, -4) ]) #Odstranili smo 1. in 4. stolpec v tabeli s podatki in ocenili opisno statistiko s funkcijo summary
## Noga Starost Visina Starost1
## Min. :37.00 Min. :19.00 Min. :160.0 Min. :20.00
## 1st Qu.:37.75 1st Qu.:21.25 1st Qu.:163.0 1st Qu.:22.25
## Median :39.00 Median :23.50 Median :169.7 Median :24.50
## Mean :39.50 Mean :23.00 Mean :169.6 Mean :24.00
## 3rd Qu.:40.75 3rd Qu.:25.25 3rd Qu.:176.2 3rd Qu.:26.25
## Max. :43.00 Max. :26.00 Max. :179.0 Max. :27.00
mean(podatki$Starost)
## [1] 23
sd(podatki$Visina)
## [1] 9.025289
#install.packages("psych")
library(psych)
describe(podatki)
## vars n mean sd median trimmed mad min max range skew kurtosis
## ID 1 4 2.50 1.29 2.50 2.50 1.48 1 4 3 0.00 -2.08
## Noga 2 4 39.50 2.65 39.00 39.50 2.22 37 43 6 0.32 -2.01
## Starost 3 4 23.00 3.16 23.50 23.00 2.97 19 26 7 -0.24 -2.12
## Spol* 4 4 1.50 0.58 1.50 1.50 0.74 1 2 1 0.00 -2.44
## Visina 5 4 169.57 9.03 169.65 169.57 11.12 160 179 19 -0.01 -2.31
## Starost1 6 4 24.00 3.16 24.50 24.00 2.97 20 27 7 -0.24 -2.12
## se
## ID 0.65
## Noga 1.32
## Starost 1.58
## Spol* 0.29
## Visina 4.51
## Starost1 1.58
#install.packages("pastecs")
library(pastecs)
round(stat.desc(podatki[ , c(-1, -4) ] ), 2)
## Noga Starost Visina Starost1
## nbr.val 4.00 4.00 4.00 4.00
## nbr.null 0.00 0.00 0.00 0.00
## nbr.na 0.00 0.00 0.00 0.00
## min 37.00 19.00 160.00 20.00
## max 43.00 26.00 179.00 27.00
## range 6.00 7.00 19.00 7.00
## sum 158.00 92.00 678.30 96.00
## median 39.00 23.50 169.65 24.50
## mean 39.50 23.00 169.57 24.00
## SE.mean 1.32 1.58 4.51 1.58
## CI.mean.0.95 4.21 5.03 14.36 5.03
## var 7.00 10.00 81.46 10.00
## std.dev 2.65 3.16 9.03 3.16
## coef.var 0.07 0.14 0.05 0.13