English version
Na ovim stranicama ćete naći prezentacije, kod, i predloge za čitanje za kurs Uvod u R za Data Science koji organizujemo u saradnji sa Data Science zajednicom Srbije.
Predavači na kursu su, dipl. ing Branko Kovač, Data Analyst at CUBE, Data Science Mentor at Springboard, Institut savremenih nauka, Data Science zajednica Srbije, i dr Goran S. Milovanović, DataScientist@DiploFoundation, Data Science zajednica Srbije.
Neke strukture podataka, data.frame, ilustracija na primeru jednostavnog linearnog regresionog modela. Ilustrativni pregled programskog jezika R na primerima. Upoznavanje sa radom u RStudio razvojnom okruženju. Šta sve to R može i kako ga naterati da izvede najjednostavnije trikove koje ćemo vući u Data Science? Šta je to CRAN repozitorijum R paketa, šta su uopšte R paketi i kako se instaliraju
R je vektorski programski jezik, što znači da u R programiranju treba maksimalno da iskoristimo mogućnost lake i brze manipulacije vektorima i matricama. S druge strane, mnogo rada u R je bazirano na upotrebi lista. Naučićemo osnove baratanja sa ovim strukturama podataka.
R je viši programski jezik u kome je lista često korišćen tip podataka. Tokom ove sesije upoznajemo se radom sa tim dinamičkim tipom. R je takođe funkcionalan programski jezik: praktično sve što se “dešava” u R jeste poziv i izvršenje neke funkcije (čak su i operatori u R, i oni najosnovniji – funkcije). Učimo da radimo sa funkcijama. Kombinujemo funkcije i rad sa listama učeći veoma korisnu lapply(), a zatim demonstriramo kako se njena “rođaka”, apply(), primenjuje na matrice po dimenzijama.
Sada već programiramo u R, učimo kako se formiraju i pozivaju funkcije, struktuiramo naš kod i spremamo se na rad u različitim R paketima. Kontrola toka je sigurno u našim rukama, lako baratamo svim osnovnim tipovima podataka kojima R raspolaže. Na kraju sesije 4, poredimo programiranje upotrebom standardne kontrole toka (npr. for petlja) i vektorizaciju koda u R. Ovo je funkcionalni, vektorski programski jezik: skoro po pravilu, ako petlja u kodu ne mora da se pojavi, ona i ne treba da se pojavi – jer to kupuje brzinu egzekucije R interepretera.
Jedna od stvari po kojima se savremena Data Science razlikuje od prethodnog rada u različitim oblastima analitike podataka je to što smo danas često primorani da se bavimo struktuiranjem nestruktuiranih ili polustruktuiranih informacija, najčešće prikupljenih sa interneta. To mahom znači puno, puno manipulacije stringovima. Uvod u upotrebu R kapaciteta i paketa za rad sa stringovima. Priča za sebe: regularni izrazi u R.
Na osnovu vrednosti jedne varijable, pod određenim uslovima koji moraju biti zadovoljeni, u stanju smo da predviđamo vrednost neke druge varijable. Na osnovu nečije težine, makar i neprecizno, možemo da predvidimo koliko je ta osoba visoka, ili koji broj cipela nosi. U tržišnim istraživanjima, neko može da nam naruči da na osnovu nekog raspoloživog znanja o kupcima određenog proizvoda predvidimo kako će se on prodavati. Učimo osnovni model ovakve vrste prediktivnog rada u R, model jednostavne linearne regresije.
Na osnovu poznavanja vrednosti više varijabli, pod određenim uslovima koji moraju biti zadovoljeni, u stanju smo da predviđamo vrednost neke varijable koja nije među njima. Učimo model multipla regresione analize u kome ćemo već upoznati većinu problema sa kojima se suočavamo u prediktivnom poslu u Data Science. Kako da pokušamo da predvidimo ponašanje nekoga ili nečega na osnovu prikupljenog velikog broja varijabli tj. osobina te osobe ili tog fenomena? Multipla regresija je verovatno najjednostavniji odgovor na ovo veoma komplikovano pitanje.
Na osnovu poznavanja toga u koju od dve kategorije neka stvar spada, pokušavamo da kažemo što više možemo o tome zbog kojih njenih osobina – kojih može biti i veliki broj – se ona nalazi baš tamo. Pošto se rešimo problema binomijalne logističke regresije u R, sažetog u prvoj rečenici, prelazimo na složeniji problem multinomijalne logističke regresije: na osnovu znanja o tome iz koje od više raspoloživih kategorija dolazi neka stvar, pokušavamo da zaključimo zbog kojih njenih osobina se ona našla baš tamo? Interesantno, jednom kada znamo koje osobine vode u koju kategoriju stvari, mi možemo da rešimo klasifikacije prethodno neklasifikovanih objekata, što je jedan od najčešćih poslova koje će Data Scientist imati.
Postoji veliki, veliki broj osobina kojima ste opisali određeni skup objekata. Neko traži od vas da napravite pregled te vaše analize i da rezultate prikažete vizuelno što jasnije. Avaj, vi ste problem opisali preko 100 karakteristika, a ljudski vizuelni sistem trpi dve do tri dimenzije: šta sad? Redukcija dimenzionalnosti je posao sa kojim se u Data Science srećemo skoro svaki dan: kako svesti obilje karakteristika stvari na manji broj karakterstika, a izgubiti pri tom što je manje moguće korisnih informacija? Razmatramo tek jedno moguće rešenje primenom multidimenzionalnog skaliranja u programskom jeziku R.
Popularnost neparametrijskih statističkih metoda već duže od deceniju dobija na zamahu, zahvaljući pre svega tome što se odlikuju pretpostavkama mnogo “jeftinijim” od uobičajenih. Završavamo sa pregledom osnovnih neparametrijskih metoda u R: kada ih i zašto koristimo, i kako?
U Startit Centru održali smo prvu sesiju kursa Uvod u R za Data Science u četvrtak, 28. aprila 2016. Kao što smo obećali, pregled kursa i svi nastavni materijali će biti dostupni online za sve koji ne mogu da nam se priključe u Startit Centru – zbog ograničenog kapaciteta kursa na 15 polaznika – a žele da prođu kroz Uvod u R za Data Science sa nama. Ovde ćemo, posle svake održane sesije kursa, predstavljati te materijale sa komentarima, dodatnim uputsvima, i preporukama za dalje čitanje i učenje.
U skladu sa prethodno iznetim, molimo sve koje ovom prilikom nismo mogli da pozovemo da prisustvuju kursu u Startit Centru da počnu da uče ovde i ipak ne dolaze na sesije in situ. Organizovaćemo još ovakvih kurseva sigurno, pa ćemo javiti kada bude bilo kapaciteta za još polaznika. Osim što je rad sa više od petnest polaznika prezahtevan za predavače na ovakvom kursu, ako dopustimo učešće i onima koje nismo pozvali ovaj put pravimo i nepravdu prema nekih dvesta i nešto kandidata koji su želeli da rade sa nama a mi nismo mogli da im izađemo u susret. Molimo vas zato da imate razumevanja za ograničenje kapaciteta kursa i da, ako niste pozvani u Startit Centar ovaj put, počnete – do sledeće prilike – sa učenjem R i data science na ovim stranicama.
Uvod u R za Data Science :: Sesija 1 [Intro to R for Data Science :: Session 1]
from Goran Milovanović######################################################## # Introduction to R for Data Science # SESSION 1 :: 28 April, 2016 # Data Science Community Serbia + Startit # :: Branko Kovač and Goran S. Milovanović :: ######################################################## # This is an R comment: it begins with "#" and ends with nothing # data source: http://www.stat.ufl.edu/~winner/datasets.html (modified, from .dat to .csv) # from the website of Mr. Larry Winner, Department of Statistics, University of Florida # Data set: RKO Films Costs and Revenues 1930-1941 # More on RKO Films: https://en.wikipedia.org/wiki/RKO_Pictures # First question: where are we? getwd(); # this will tell you the path to the R working directory # Where are my files? filesDir <- "/home/goran/Desktop/__IntroR_Session1/"; class(filesDir); # now filesDir is a of a character type; there are classes and types in R typeof(filesDir); # By the way, you do not need to use the semicolon to separate lines of code: class(filesDir) typeof(filesDir) # point R to where your files are stored setwd(filesDir); # set working directory getwd(); # check # Read some data in csv (comma separated values # - it might turn out that you will be using these very often) fileName <- "rko_film_1930-1941.csv"; dataSet 0; reRelease; is.logical(reRelease); # vectors, sequences... # automatic type conversion (coercing) in R: from real to integer x
# hm, maybe I should use non-parametric correlation instead
cSpearman
# However, who in the World tests the assumptions of the linear model... Kick it!
reg
# Q1: Is this model any good? # Q2: Are there any truly dangerous outliers present in the data set? # print is also a generic function in R: for example, print("Doviđenja i uživajte u praznicima uz gomilu materijala za čitanje i vežbu!") # P.S. Play with: reg
Prvih pet poglavlja knjige The Art of R Programming, pokrivaju: uvod u R, vektore, matrice i liste. Na Sesiji 2. će Branko postepeno preći ka data.frame tipu koji je Goran već diskutovao na Sesiji 1, ali sa manje teorijskim i više praktičnim pristupom. Ipak, nećete moći daleko u R bez vektora, matrica, i lista, te je zato ovakav izbor čitanja za narednu sesiju. Pripremite sva pitanja koja možete da imate na osnovu čitanja knjige!
The Art of R Programming, Norman Matloff
Chapter 1 – 5, pp. 1 – 54.
U Startit Centru održali smo drugu sesiju kursa Uvod u R za Data Science u četvrtak, 5. maja 2016. Sesiju je vodio Branko Kovač i sa polaznicima diskutovao osnove baratanja vektorima, matricama, i data.frame objektima u programskom jeziku R. Dogovorili smo se da čitanje za Sesiju 3. ne bude uvećano već ostane pri prvih pet poglavlja knjige The Art of R Programming.
######################################################## # Introduction to R for Data Science # SESSION 2 :: 5 May, 2016 # Data Science Community Serbia + Startit # :: Goran S. Milovanović and Branko Kovač :: ######################################################## # clear all rm(list=ls()); # Let\'s start with some vectors char_list <- character(length = 0) #empty character list num_list <- numeric(length = 10) #length can be != 0, but 0 is default value log_list <- logical(length = 3) #default value is FALSE # But you can always use good ol\' c() for the same purpose log_list_2 <- c(TRUE, FALSE, FALSE, TRUE, TRUE, TRUE) #some Ts and Fs num_list_2 <- c(1, 4, 12, NA, 101, 999) #numb char_list_2 <- c("abc", "qwerty", "test", "data", "science") # Factor vectors are also part of R fac_list <- gl(n = 4, k = 1, length = 8, ordered = T, labels = c("low", "med", "high", "very high")) #only mentioning now 🙂 # Subsetting is regular-thing-to-do when using R char_list_2[5] #single element can be selected log_list_2[2:4] #or some interval num_list_2[3:length(num_list_2)] #or even length() function # New objects can be created when subsetting test <- num_list_2[-c(2,4)] #or somthing like this - displays all but 2nd and 4th element test_2 <- num_list_2 %in% test #operator %in% can be very useful not_na <- num_list_2[!is.na(num_list_2)] #removing NAs using operator ! and is.na() function # Vector ordering sort(test, decreasing = T) #using sort() function test[order(test, decreasing = T)] #or with order() function # Vector sequences seq(1,22,by = 2) #we already mentioned seq() rep(1, 4) #but rep() is something new 🙂 rep(num_list_2, 2) #replicate num_list_2, 2 times # Concatenation new_num_vect <- c(num_list, num_list_2) #using 2 vectors to create new one new_num_vect new_combo_vect <- c(num_list_2, log_list) #combination of num and log vector new_combo_vect #all numbers? false to zero? coercion in action new_combo_vect_2 <- c(char_list_2, num_list_2) #works as well new_combo_vect_2 #where are the numbers? class(new_combo_vect_2) #all characters # Matrices are available in R matr <- matrix(data = c(1,3,5,7,NA,11), nrow = 2, ncol = 3) #2x3 matrix class(matr) #yes, it\'s matrix typeof(matr) #double as expected matr[,2] #2nd column matr[3,] #oops, out of bounds, there\'s no 3rd row matr[2,3] #element in 2nd row and 3rd column matr_2 <- matrix(data = c(1,3,5,"7",NA,11), nrow = 2, ncol = 3) #another 2x3 matrix class(matr_2) #matrix again typeof(matr_2) #but not double anymore, type conversion in action! t(matr_2) #transponed matr_2 # What can we do if a matrix needs to encompass different types of data? # Introducing data frame! library(datasets) #there are some datasets in base R like mtcars cars_data <- mtcars # Some useful information about data frames str(cars_data) #lets see what we have here summary(cars_data) #more information about mtcars dataset names(cars_data) #column names ?mtcars #dataset documentation is *very* important # Think of data frame columns as vectors! Because they are! mean(cars_data$mpg) #mean of cars_data mpg (miles per galon) column median(cars_data$cyl) #median of cars_data cyl (cylinders) column is.list(cars_data[1,]); #but rows are lists! # Lets do some data frame subsetting cars_data[-1, ] # first row out cars_data[ ,-1] # first column out cars_data[c(1,3)] #keeping 1st and 3rd column only cars_data[-c(1,3)] #removing 1st and 3rd column cars_data[ ,-c(1,3)] #same as the previous line of code cars_data[!duplicated(cars_data$mpg), ] #maybe we want to remove all cars with same mpg? #remember it keeps only the first occurence! subset(cars_data, mpg < 19) #this is one way (and it can be slow!) cars_data[cars_data$mpg < 19, ] #this is another one (faster) cars_data[which(cars_data$mpg < 19), ] #and another one (usually even more faster) cars_data[cars_data$mpg > 20 & cars_data$am == 1, ] #multiple conditions cars_data[grep("Merc", row.names(cars_data), value=T), ] #filtering by pattern match # Data frame transformations cars_data$trans <- ifelse(cars_data$am == 0, "automatic", "manual") #we can add new colums cars_data$trans <- NULL #or we can remove them cars_data[c(1:3,11,4,7,5:6,8:10)] #this way we change column order # Separation and joining of data frames low_mpg <- cars_data[cars_data$mpg < 15, ] #new data frame with mpg < 15 high_mpg <- cars_data[cars_data$mpg >= 15, ] #new data frame with mpg >= 15 mpg_join <- rbind(low_mpg, high_mpg) # we can combine 2 data frames like this car_condition <- data.frame(sample(c("old","new"), replace = T, size = 32)) #creating random data frame #with "old" and "new" values names(car_condition) <- "condition" #for all kinds of objects colnames(car_condition) <- "condition" #for "matrix-like" objects, but same effect here rownames(car_condition) <- rownames(cars_data) #use row names of one data frame as row names of other mpg_join <- cbind(mpg_join, car_condition) #or combine data frames like this
Prvih pet poglavlja knjige The Art of R Programming, pokrivaju: uvod u R, vektore, matrice i liste. Na Sesiji 3, po svemu sudeći, idemo na liste, objekte, i elemente kontrole toka u R. Pripremite sva pitanja koja možete da imate na osnovu čitanja knjige!
U Startit Centru održali smo treću sesiju kursa Uvod u R za Data Science u četvrtak, 12. maja 2016. Sesija je bila posvećena radu sa listama i funkcijama u R, temama kojima smo u međuvremenu odlučili da posvetimo više vremena u odnosu na početni plan. Knjiga The Art of R Programming liste pokriva u poglavlju 5, a funkcije u poglavlju 9. Bližimo se kraju uvodnog dela kursa: pošto naučimo i kontrolu toka u R tokom sledeće sesije, pokrili smo prvih deset poglavlja knjige, osim faktora (poglavlje 7) koje ćemo već sresti tokom analitike u drugoj polovini kursa.
######################################################## # Introduction to R for Data Science # SESSION 3 :: 12 May, 2016 # Data Science Community Serbia + Startit # :: Goran S. Milovanović and Branko Kovač :: ######################################################## # clear all rm(list=ls()); # It's time to speak about lists num_vct <- c(2:5) # just another num vector chr_vct <- c("data", "science") # char vector data_frame <- data.frame(x = c("a", "b", "c", "d"), y = c(1:4)) # simple df lista <- list(data_frame, num_vct, chr_vct) # and this is a list lista # this is our list str(lista) # about a list length(lista) as.list(chr_vct) # another way to create a list # Lists manipulation names(lista) <- c("data", "numbers", "words") lista[3] # 3rd element? lista[[3]] # 3rd element? is.list(lista[3]) # is this a list? is.list(lista[[3]]) # and this? class(lista[[3]]) # also a list? not be so sure! lista$words # we can also extract an element this way lista[["words"]] # or even like this length(lista$words) # 2 as expected lista[["words"]][1] # digging even deeper lista$new_elem <- c(TRUE, FALSE, FALSE, TRUE) # add new element length(lista) # now list has 4 elements lista$new_elem <- NULL # but we can remove it easily new_vect <- unlist(lista) # creating a vector from list # Introduction to Functions in R # (w. less formalism but tips & tricks added) # elementary: a defition of a function in R fun <- function(x) x+10; fun(5) # taking two arguments fun2 <- function(x,y) x+y; fun2(3,4) # using "{" and "}" to enclose multiple R expresions in the function body fun <- function(x,y) { a <- sum(x); b <- sum(y); a-b } r <- c(5,4,3); q <- c(1,1,1); fun(r,q) fun(c(5,4,3),c(1,1,1)) # NOTE: "{" and "}" are generally used in R to mark the beginning and the end of block # a function is a function: is.function(fun); is.function(log); # log is built-in # printing function to acess their source code; fun log # try: is.primitive(log); this one is written in C, belongs to the base package - it's "under the hood" # Built in functions + functional programming ("Everything is a function...") "^"(2,2) "^"(2,3) # magic! - how do you do that? 2^2 2^3 # the difference between "operators" and "functions" in R: none. Everything is a function: "+"(2,2) # Four? 2+2 # yeah, right # Oh but I love this "-"("+"(3,5),2); "&"(">"(2,2),T); "&"(">"(3,2),T); # punishment: write all your lab code for this week in this fashion... # built in functions: x <- 16; sqrt(x); x <- c(1,2,3,4,5,6,7,8,9); mean(x); # whatch for NAs in statistics (!) x <- c(1,2,3,4,5,6,7,8,NA); mean(x); mean(x, na.rm = T); # right! median(x); sd(x); sum(x); sum(x, na.rm = T); # a-ha! # Lexical scoping in R + nested functions # example taken from: http://adv-r.had.co.nz/Functions.html # "Advanced R" by Hadley Wickham # ";"s added by GSM x <- 1; h <- function() { y <- 2; i <- function() { z <- 3 c(x, y, z) } i(); } h(); # Messing up argument names (never do this in nested functions unless you have to) rm(x, h); x <- 1; h <- function(x) { y <- x+1 i <- function(x) { z <- x+2; z } z <- i(x); c(x,y,z) } h(x) # Two things that come handy: lapply and apply # Step 1: here's a list: aList <- list(c(1,2,3), c(4,5,6), c(7,8,9), c(10,11,12)); # Step 2: I want to apply the following function: myFun <- function(x) { x[1]+x[2]-x[3] } # to all elements of the aList list, and get the result as a list again. Here it is: res <- lapply(aList, function(x) { x[1]+x[2]-x[3] }); unlist(res) # to get a vector rm(myFun); # Now say I've got a matrix myMat <- matrix(c(1,2,3,4,5,6,7,8,9), nrow=3, ncol=3); # btw is.function(matrix); # reminder class(myMat); typeof(myMat); # now, I want the sums of all rows: rsMyMat <- apply(myMat, 1, function(x) { sum(x) }); rsMyMat; is.list(rsMyMat) # just beatiful # for columns: csMyMat <- apply(myMat, 2, function(x) { sum(x) }); # with existings functions such as sum(), this will do: rsMyMat1 <- apply(myMat, 1, sum); rsMyMat1 csMyMat1 <- apply(myMat, 2, sum); csMyMat1
Konačno, trebalo bi da do sesije 4. pređete svih prvih deset poglavlja knjige “The Art of R Programming”; ne morate da se bavite faktorima (poglavlje 7) jer ćemo ih svakako sresti negde tokom drugog dela kursa kada budemo radili sa statističkim modelima u R. Pripremite sva pitanja koja možete da imate na osnovu čitanja knjige!
U Startit Centru održali smo i četvrtu sesiju kursa Uvod u R za Data Science u četvrtak, 19. maja 2016. Prešli smo različite forme kontrole toka u R, tako da smo sada u stanju da kombinujemo strukture podataka, kontrolu toka, i funkcije u kompletne R skripta za najrazličitije namene. Posebnu pažnju posvetili smo vektorizaciji koda u R. Vektorizacija koda (mahom!) rezultira u velikom ubrzanju računice u R, što je za potrebe rada u Data Science od ključnog značaja.
######################################################## # Introduction to R for Data Science # SESSION 3 :: 12 May, 2016 # Data Science Community Serbia + Startit # :: Goran S. Milovanović and Branko Kovač :: ######################################################## # clear all rm(list=ls()); # It's time to speak about lists num_vct <- c(2:5) # just another num vector chr_vct <- c("data", "science") # char vector data_frame <- data.frame(x = c("a", "b", "c", "d"), y = c(1:4)) # simple df lista <- list(data_frame, num_vct, chr_vct) # and this is a list lista # this is our list str(lista) # about a list length(lista) as.list(chr_vct) # another way to create a list # Lists manipulation names(lista) <- c("data", "numbers", "words") lista[3] # 3rd element? lista[[3]] # 3rd element? is.list(lista[3]) # is this a list? is.list(lista[[3]]) # and this? class(lista[[3]]) # also a list? not be so sure! lista$words # we can also extract an element this way lista[["words"]] # or even like this length(lista$words) # 2 as expected lista[["words"]][1] # digging even deeper lista$new_elem <- c(TRUE, FALSE, FALSE, TRUE) # add new element length(lista) # now list has 4 elements lista$new_elem <- NULL # but we can remove it easily new_vect <- unlist(lista) # creating a vector from list # Introduction to Functions in R # (w. less formalism but tips & tricks added) # elementary: a defition of a function in R fun <- function(x) x+10; fun(5) # taking two arguments fun2 <- function(x,y) x+y; fun2(3,4) # using "{" and "}" to enclose multiple R expresions in the function body fun <- function(x,y) { a <- sum(x); b <- sum(y); a-b } r <- c(5,4,3); q <- c(1,1,1); fun(r,q) fun(c(5,4,3),c(1,1,1)) # NOTE: "{" and "}" are generally used in R to mark the beginning and the end of block # a function is a function: is.function(fun); is.function(log); # log is built-in # printing function to acess their source code; fun log # try: is.primitive(log); this one is written in C, belongs to the base package - it's "under the hood" # Built in functions + functional programming ("Everything is a function...") "^"(2,2) "^"(2,3) # magic! - how do you do that? 2^2 2^3 # the difference between "operators" and "functions" in R: none. Everything is a function: "+"(2,2) # Four? 2+2 # yeah, right # Oh but I love this "-"("+"(3,5),2); "&"(">"(2,2),T); "&"(">"(3,2),T); # punishment: write all your lab code for this week in this fashion... # built in functions: x <- 16; sqrt(x); x <- c(1,2,3,4,5,6,7,8,9); mean(x); # whatch for NAs in statistics (!) x <- c(1,2,3,4,5,6,7,8,NA); mean(x); mean(x, na.rm = T); # right! median(x); sd(x); sum(x); sum(x, na.rm = T); # a-ha! # Lexical scoping in R + nested functions # example taken from: http://adv-r.had.co.nz/Functions.html # "Advanced R" by Hadley Wickham # ";"s added by GSM x <- 1; h <- function() { y <- 2; i <- function() { z <- 3 c(x, y, z) } i(); } h(); # Messing up argument names (never do this in nested functions unless you have to) rm(x, h); x <- 1; h <- function(x) { y <- x+1 i <- function(x) { z <- x+2; z } z <- i(x); c(x,y,z) } h(x) # Two things that come handy: lapply and apply # Step 1: here's a list: aList <- list(c(1,2,3), c(4,5,6), c(7,8,9), c(10,11,12)); # Step 2: I want to apply the following function: myFun <- function(x) { x[1]+x[2]-x[3] } # to all elements of the aList list, and get the result as a list again. Here it is: res <- lapply(aList, function(x) { x[1]+x[2]-x[3] }); unlist(res) # to get a vector rm(myFun); # Now say I've got a matrix myMat <- matrix(c(1,2,3,4,5,6,7,8,9), nrow=3, ncol=3); # btw is.function(matrix); # reminder class(myMat); typeof(myMat); # now, I want the sums of all rows: rsMyMat <- apply(myMat, 1, function(x) { sum(x) }); rsMyMat; is.list(rsMyMat) # just beatiful # for columns: csMyMat <- apply(myMat, 2, function(x) { sum(x) }); # with existings functions such as sum(), this will do: rsMyMat1 <- apply(myMat, 1, sum); rsMyMat1 csMyMat1 <- apply(myMat, 2, sum); csMyMat1
Konačno, trebalo bi da do sesije 4. pređete svih prvih deset poglavlja knjige “The Art of R Programming”; ne morate da se bavite faktorima (poglavlje 7) jer ćemo ih svakako sresti negde tokom drugog dela kursa kada budemo radili sa statističkim modelima u R. Pripremite sva pitanja koja možete da imate na osnovu čitanja knjige!
You must be logged in to post a comment.