Professional Documents
Culture Documents
Ilajla
Ilajla
y <- -4:5
theDF
nrow(theDF)
ncol(theDF)
dim(theDF)
names(theDF)
names(theDF)[3]
rownames(theDF)
rownames(theDF)
rownames(theDF)
class(theDF)
theDF$Sport
theDF[3, 2]
theDF[3, 2:3]
theDF[, 3]
theDF[, 2:3]
theDF[2, ]
##Još jedan način da se pristupi određenoj koloni je da se ime njenog stupca (ili njegov broj) koristi ili kao drugi argument u
uglatim zagradama ili kao jedini argument u pojedinačne ili dvostruke uglate zagrade
theDF[, "Sport"]
class(theDF[, "Sport"])
theDF["Sport"]
class(theDF["Sport"])
#drop = FALSE.
#ova cinjenjica vam je bitna usled operacija koje se izvode nad matricama
list(1, 2, 3)
list(c(1, 2, 3))
list(theDF, 1:10)
names(list5)
names(list5)
length(list5)
names(list6)
#Matrice
nrow(A)
ncol(A)
dim(A)
A + B #sabiranje
A * B # mnozenje
A == B # provera jedakosti
#redova desne matrice. A i B su 5x2, transponovati ćemo B da bi se mogao koristiti sa desne strane.
A %*% t(B)
colnames(A)
rownames(A)
colnames(B)
rownames(B)
colnames(C)
rownames(C)
t(A)
A %*% C
#Niz
theArray
theArray[1, , ]
theArray[1, , 1]
theArray[, , 1]
install.packages("readxl")
library("readxl")
library(ggplot2)
data(diamonds)
head(diamonds)
#Base Histograms
#Base Scatterplot
plot(diamonds$carat, diamonds$price)
#Boxplots
boxplot(diamonds$carat)
#Ideja iza box plot je da debela srednja linija predstavlja srednju vrednost,
#ggplot2
ggplot(data=diamonds) + geom_histogram(aes(x=carat))
#ggplot2 Scatterplots
g <-ggplot(diamonds,aes(x=carat, y=price))
g + geom_point(aes(color=color))
g + geom_point(aes(color=color)) + facet_wrap(~color)
ggplot(diamonds, aes(x=carat)) + geom_histogram() + facet_wrap(~color)
as.numeric(TRUE)
as.numeric(FALSE)
1 == 1
1<1
1 <= 1
1>1
1 >= 1
toTest[2] <- NA
b <- c(2, 1, 0, 1)
#funkcije
x*2
double.num(5)
# boolean funkcija
if(x == 1)
print("hello")
}else
print("goodbye")
check.bool(1)
check.bool(0)
#switch finkcija
switch(x,
"a"="first",
"b"="second",
"z"="last",
"c"="third",
"other")
use.switch("b")
use.switch("c")
use.switch("d")
use.switch("e")
use.switch("z")
#FOR funkcija
for(i in 1:10)
print(i)
for(a in fruit)
}
fruitLength
apply(theMatrix, 1, sum)
apply(theMatrix, 2, sum)
rowSums(theMatrix)
colSums(theMatrix)
theList[["A"]]
theList[["B"]]
theList[["C"]]
theList[["D"]]
lapply(theList, sum)
#funkcija aggregate
data(diamonds, package='ggplot2')
head(diamonds)
select(diamonds, 1, 7)