Príklad
# Working with data frames
Meno = c("Peter", "Fero", "Jano")
Vek = c(14, 18, 15)
Body = c(75, 62, 90)
udaje <- data.frame(Meno,Vek,Body)
print(udaje)
print(udaje$Vek) # takto adresujeme jednotlivé premenné v data.frame
[1] 14 18 15
print(mean(udaje$Vek)) # priemerny vek
[1] 15.66667
print(udaje[Meno=="Peter",]) # adresovanie celého riadku
print(udaje[3,]) # ina moznost adresovania celeho riadku
print(udaje[,2:3]) # vypisanie druheho a tretieho stlpca tabulky
print(udaje[1,1]) # vypisanie jednej bunky tabulky
[1] "Peter"
summary(udaje) # zakladna deskriptivna statistika celej tabulky
Meno Vek Body
Length:3 Min. :14.00 Min. :62.00
Class :character 1st Qu.:14.50 1st Qu.:68.50
Mode :character Median :15.00 Median :75.00
Mean :15.67 Mean :75.67
3rd Qu.:16.50 3rd Qu.:82.50
Max. :18.00 Max. :90.00
MaBicykel <- c(TRUE,TRUE,FALSE)
udaje <- cbind(udaje,MaBicykel)
print(udaje)
# New record (must match column order/types)
novy.riadok <- data.frame(Meno = "Martin", Vek = 17, Body = 52,MaBicykel = FALSE)
# Append
udaje <- rbind(udaje, novy.riadok)
print(udaje)
novy.riadok <- data.frame(Meno = "Izidor", Vek = 16, Body = 95,MaBicykel = TRUE)
udaje <- rbind(udaje, novy.riadok)
print(udaje)
Športuje <- c(FALSE,FALSE,TRUE,TRUE,FALSE)
udaje <- cbind(udaje,Športuje)
print(udaje)