https://www.w3schools.com/r/default.asp https://cran.r-project.org/doc/manuals/r-release/R-intro.html https://www.jdoodle.com/execute-r-online/ ls() - listowanie nazw zmiennych rm(x,y) # remove Ctrl+L - czysci konsole (nie czysci zmiennych) mtcars x=c(1:100) x<-1:20 #komentarz toString(44) i<-2; while(i<7){print(i);i<-i+1} x <- seq(-3,3,len=31) x<-seq(-3,3,by=0.1) rep(x, times=5) x <- 1:20; Data <-data.frame(x=x,y=rnorm(x)) m=matrix(c(1,2,3,4,5,6), nrow = 3, ncol = 2) m[1, 2] m[,2] m[2,] m[c(1,2),] arrays can have more than two dimensions f = data.frame (k1 = c("A", "B", "C"), k2 = c(100, 150, 120), k3 = c(60, 30, 45)) summary(f) f[1] hist(x) sort(x) order() boxplot(x) sample(0:6, 1) - rzut kostką ecdf(x) - emp. kumul. y=scale(x) y=(x-mean(x))/sd(x) ifelse(1<2,5,6) =5 x=rnorm(100); r=0.9; y=r*x+(1-r^2)*rnorm(100); plot(x,y); f=data.frame(y,x); reg=lm(f); summary(reg) y1=x*summary(reg)$coefficients[2,1]+summary(reg)$coefficients[1,1] (pod ,2] mamy błędy, pod 4 p-value) plot(x,y,ylim=c(-3,3)); par(new = TRUE); plot(x,y1,col='red',ylim=c(-3,3)) plot(1:10, type="l", col="blue", lwd=2) gruba linia plot(line1, type = "l", col = "blue"); lines(line2, type="l", col = "red") lub points(x2, y2, col="blue", cex=2) for (k in 1:12){ 12 osobnych wykresow po 4 obrazki kazdy, na kazdym kilka linii dev.new(width=15, height=5); par(mfcol=c(1,4)) for (i in 0:3){ plot(x); lines(t,x,col="red"); for (n in 1:4){lines(c(-3,10),c(pp[n],pp[n]),col="green")}}} x <- c(10,20,30,40); pie(x) x <- c("A", "B", "C", "D"); y <- c(2, 4, 6, 8); barplot(y, names.arg = x) y=c(); for (i in 1:70){if (x[i]>0) {y= append(y,x[i])} else {y= append(y,0)}}} i<-2; while(i<7){print(i);i<-i+1} p = read.table("E:\\Różne\\Prokop\\data.txt", header = FALSE) write.csv(SPI,file="E:\\Różne\\Prokop\\SPI.txt") save(x,file="C:\\Users\\Laurem\\Desktop\\zajecia\\x.RData") load("C:\\Users\\Laurem\\Desktop\\zajecia\\x.RData") > install.packages("smatr") > library(smatr) ?sin help.search("fourier") toString(44) rep(x, times=5) x <- seq(-3,3,len=31) x<-seq(-3,3,by=0.1) -3.0 -2.8 -2.6 ... 2.8 3.0 i<-2; while(i<66){y <- as.numeric(c(Ar[1:365,i])); z <- supsmu(x, y, span = "cv", periodic = FALSE, bass = 0) write.table(z[2],file=paste("D:/Ludzie/Idalia/zebrane_dane",toString(i),".txt",sep="")) i<-i+1} for (rows in 1:nrow(thismatrix)) { for (columns in 1:ncol(thismatrix)) { print(thismatrix[rows, columns]) } } r=0.9; y=r*x+(1-r^2)*rnorm(100); plot(x,y) *** R E G R E S J A *** f=data.frame(y,x); reg=lm(f); summary(reg) **** x<-rnorm(30); e<-rnorm(30)/10; y<-x^2+x*0.1+e; plot(x,y) Reg<-lm(formula = y~x+I(x^2)); summary(Reg) x=rnorm(1000); y=rnorm(1000) *** P C A *** x1=x+y; x2=x-y; x3=x+0.1*y; x4=0.1*x+y; x5=x+0.2*rnorm(1000); x6=rnorm(1000) f=data.frame(x1,x2,x3,x4,x5,x6) pca=prcomp(f) plot(pca$sdev) plot(pca$x[,1],pca$x[,2]) cor(pca$x[,1],pca$x[,2]) d = read.table("D://AGH//zajecia21//R//doPCA.txt", header = TRUE) d = read.table("D://AGH//zajecia21//R//plodnosc_pca.txt", header = TRUE) pca = prcomp(d) p1=pca$x[,1] x=rnorm(128); t=c(0:127); rep(0,128) *** F F T *** s=sin(2*pi/32*t); x0=x; x=x+s y=fft(x); y[2]; y[128] z=exp(2i*pi/32*t) ym=Mod(y); ym=ym[1:65] f=c(0:64) plot(f,ym,type='b',col='blue',axes=FALSE); axis(side=1, at=c(0:64)) plot(t,x,type='l') plot(x); par(new = TRUE); plot(x1) - dwa na jednym Arg(y[2]) length(x) x=rep(0,1000); for(i in 1:j){f=i*2-1; x=x+1/f}; plot(x) - cztery wykresy. ARRAY and MAHALONOBIS x<-c(0,0.1,0.2); y<-c(0,1,2); z<-outer(x,y,FUN="+"); x; y; z cov <- array(c(1, 0.9, 0.9, 1), c(2,2)) w1<-c(0,1); w2<-c(1,0) (w2-w1) %*% cov %*% (w2-w1) # quadratic form w<-c(1,1); w %*% cov %*% w OBRoT p1<-c(1,0) alpha<-1/100 rot<-array(c(cos(alpha),-sin(alpha),sin(alpha),cos(alpha)), c(2,2)) p1%*%rot a<-array(c(3,8,12,8,5,9,12,9,14),c(3,3)); x<-det(a) x1<-rnorm(1000); x2<-rnorm(1000) x<-rnorm(5000) dim(x)<-c(1000,5) x[1,] = [1] 1.664114 1.161365 1.568821 1.203283 1.134660 x[,1] = tysiąc x[,2]<-x2; x[,1]<-x1+0.5*x2; x[,2]<-x2-0.5*x1; x[,3]<-x[,3]+0.5*x1; x[,4]<-x[,4]+2*x2 cx<-cor(x) evcx<-eigen(cx) evcx[[2]][3,4] i= GRAFIKA x<-c(1,1,2,2); plot(x); abline(h=1); abline(v=1.7); abline(a=1,b=0.3) #intercept, slope x<-c(1,2,3,4,1.5); barplot(height=x) x<-seq(-3,3,by=0.1) G2<-function(x,y) f<-exp(-0.5*(x^2-2*0.9*x*y+y^2)); z<-outer(x,x,FUN=G2) image(x, x, z,col=gray((100:0)/100)) G2<-function(x,y) f<-exp(-0.5*(x^2-2*0.0*x*y+y^2)); z1<-outer(x,x,FUN=G2) G2<-function(x,y) f<-exp(-0.5*(x^2-2*0.9*x*y+y^2)); z2<-outer(x,x,FUN=G2) G2<-function(x,y) f<-exp(-0.5*(x^2-2*0.3*x*y+y^2)); z3<-outer(x,x,FUN=G2) G2<-function(x,y) f<-exp(-0.5*(x^2+2*0.5*x*y+y^2)); z4<-outer(x,x,FUN=G2) contour(x,x,z1, col = rgb(0,0,0), add = FALSE, nlevels=20, drawlabels = FALSE) contour(x,x,z2, col = rgb(1,0,0), add = TRUE, nlevels=20, drawlabels = FALSE) contour(x,x,z3, col = rgb(0.7,0,0), add = TRUE, nlevels=20, drawlabels = FALSE) contour(x,x,z4, col = rgb(0,0.7,0), add = TRUE, nlevels=20, drawlabels = FALSE) x<-seq(-3,3,by=0.1) image(x, x, outer(x,x,FUN=G2<-function(x,y) f<-exp(-0.5*(x^2-2*0.75*x*y+y^2))),col=gray((100:20)/100)) points(1,1,col="red") x<-rep(0,times=100) x<-c(x,x+1,x) y<-convolve(x,x,type="o") x<-seq(-5,5,by=0.1) y<-dnorm(x,0,1) z<-convolve(y,y,type="o") plot(x,y,type="l") x1<-seq(-10,10,by=0.1) lines(x1,z*0.1414) NN library(nnet) iris3 ir <- rbind(iris3[,,1],iris3[,,2],iris3[,,3]) ir cor(ir) targets <- class.ind( c(rep("s",50), rep("c",50), rep("v",50))) targets ir1 <- nnet(ir,targets,size=2,rang=0.1,maxit=200) summary(ir1) predict(ir1,c(5,3,5,2))