#promenna, vektor, matice a<-3 a<-c(1,2,3) vec<-c(1.1,5.3,6.4) (A<-matrix(c(1,2,3,4,5,6),2,3,byrow=T)) (B<-matrix(c(1,2,3,4,5,6),ncol=3,nrow=2,byrow=T)) # zakladni operace 3+2-6*9/(8+9-5) a<-15 b<-5 (a+b)/b # scitani vektoru a matic x<-c(1,2,3) y<-c(3,2,1) x+y z<-c(0,1,2,3) x+y+z B<-matrix(c(1,1,1,1,1,1),2,3) A-B #dimenze vektoru a matice length(a) dim(A) # Operace s promennymi #mocnina 3^2 a<-4 (a2<-a^2) x (x2<-x^2) A (A2<-A^2) # odmocnina sqrt(9) sqrt(a2) sqrt(x2) sqrt(A2) # min a max min(a) max(a) x min(x) max(x) A min(A) max(A) # absolutni hodnota (C<-(-1)*A) abs(C) (y<-c(-1,0,2,-5)) abs(y) # sum sum(x) sum(A) #zaokrouhlovani (odmocnina<-sqrt(2)) round(odmocnina, digits=3) round(odmocnina,digits=2) ceiling(odmocnina) floor(odmocnina) signif(odmocnina, digits=6) signif(odmocnina, digits=3) #vytvareni posloupnosti #CTRL+L #Clear workspace (x<-1:10) (y<-50:55) (pst1<-seq(from=0,to=1,length=1000)) (pst2<-seq(from=0,to=1,by=0.1)) vaha<-c(58.7, 61.6, 57.8, 59.5, 59.9, 53.9,63.6, 71.0, 66.1, 69.8) (divky<-rep(1,6)) (chlapci<-rep(2,4)) (pohlavi<-c(divky,chlapci)) #rbind/cbind vaha pohlavi (hmotnost<-matrix(c(vaha,pohlavi),nrow=10)) (hmotnost.c<-cbind(vaha,pohlavi)) (hmotnost.r<-rbind(vaha,pohlavi)) #podmnoziny hmotnost hmotnost[ ,1] hmotnost[ ,2] hmotnost[6, ] hmotnost[1, ] hmotnost[8,1] vyska<-c(133,132,145,129) vyska[4] apply(hmotnost,1,sum) apply(hmotnost,2,sum) #porovnavani < > == <= >= teploty<-c(10,9,9,8,8,9,11,12,13,14,16,18,18,19,18,16,15,14,14,13,13,14,14,14) hodiny<-1:24 mean(teploty) teploty==13.0 (1*(teploty==13)) 1*(teploty<13) 1*(teploty<=13) 1*(teploty>13) sum(1*(teploty==13)) sum(1*(teploty>13)) sum(1*(teploty<13)) #grafy plot(hodiny,teploty,main='Teplota 23.9.2015',xlab='cas (v h)',ylab='teplota', cex=1.2,pch=19,col='orchid4',lwd=2,bg='orchid4',type='b',xlim=c(0,25), ylim<-c(7,20)) legend(18,10,legend='teplota - 23.9',fil='orchid4') #export do .pdf souboru pdf('pocasi.pdf') plot(hodiny,teploty,main='Teplota 23.9.2015',xlab='cas (v h)',ylab='teplota', cex=1.2,pch=19,col='dodgerblue',lwd=2,bg='red',type='b',xlim=c(0,25), ylim<-c(7,20)) legend(18,10,legend='teplota - 23.9',fil='orchid4') dev.off() # prace s datovym souborem getwd() #setwd('C:/Users/Veronika/Documents') dir() getwd() (data<-read.delim('glukoza.txt',sep='',dec='.')) dim(data) (glukoza<-data$glukoza) (pohlavi<-data$pohlavi) data[pohlavi==0,] data[pohlavi==1,]