c(var1,var2,...,varn) > x<-c(1,2,3,4) > x [1] 1 2 3 4 > x2<-c(x,5,6,7,8) > x2 [1] 1 2 3 4 5 6 7 8
c(var1,var2,...,varn) > y=c('a0','a1','b0','b1') > y [1] "a0" "a1" "b0" "b1 > z=c(x,y) > z [1] "1" "2" "3" "4" "a0" "a1" "b0" "b1"
rep(x, times) > x<-rep(1,4) (1) [1] 1 1 1 1 > x<-rep(c(1,7,87),3) (2) [1,7,87] [1] 1 7 87 1 7 87 1 7 87 > x<-rep(1:4,3) (3) 1:4 seq [1] 1 2 3 4 1 2 3 4 1 2 3 4 > x<-sort(rep(1:4,3)) (4) (3) [1] 1 1 1 2 2 2 3 3 3 4 4 4
seq(start, end, increment/decrement) > x<-seq(1,4,1) [1] 1 2 3 4 > x<-seq(0,40,10) [1] 0 10 20 30 40 > x<-seq(10,2,-2) [1] 10 8 6 4 2 > x<-1:4 # [1] 1 2 3 4 > x<-10:1 # - [1] 10 9 8 7 6 5 4 3 2 1
> a=1:10 [1] 1 2 3 4 5 6 7 8 9 10 > which(a<5) [1] 1 2 3 4 > b=10:1 [1] 10 9 8 7 6 5 4 3 2 1 > which(b<5) [1] 7 8 9 10
> x<-matrix(1:8, nrow=2) [,1] [,2] [,3] [,4] [1,] 1 3 5 7 [2,] 2 4 6 8 > x<-matrix(1:8, nrow=2,byrow=t) [,1] [,2] [,3] [,4] [1,] 1 2 3 4 [2,] 5 6 7 8
data01<-data.frame(score = c(2,4,3,4), dose = c(rep(10,2),rep(100,2)), condition = rep(c('exp','control'),2)) > data01 score dose condition 1 2 10 exp 2 4 10 control 3 3 100 exp 4 4 100 control
dat01<-read.csv("http://www.matsuka.info/data_folder/temp_data01.txt", header=t) > dat01 x y z 1 11 12 13 2 21 22 23 3 31 32 33
dat02<-read.csv("http://www.matsuka.info/data_folder/temp_data02.txt", header=t, row.name=1) > dat02 x y z katsuo 11 12 13 wakame 21 22 23 tarachan 31 32 33
> dat03<-read.table("http://www.matsuka.info/data_folder/temp_data03.txt", header=t, row.name=4) > dat03 x y z sazae 11 12 13 masuo 21 22 23 tarachan 31 32 33
matrix M[ ] > dat03 x y z sazae 11 12 13 masuo 21 22 23 tarachan 31 32 33 > dat03[1,1] #1 1 [1] 11
n M[n, ] m M[, m] > dat03 x y z sazae 11 12 13 masuo 21 22 23 tarachan 31 32 33 > dat03[2,] # x y z masuo 21 22 23 > dat03[,1] #1 [1] 11 21 31
M$varName > dat03 x y z sazae 11 12 13 masuo 21 22 23 tarachan 31 32 33 > dat03$x [1] 11 21 31 > dat03$y [1] 12 22 32 > dat03$z [1] 13 23 33
> dat03 x y z sazae 11 12 13 masuo 21 22 23 tarachan 31 32 33 > colnames(dat03)<-c("var1","var2","var3") > dat03 var1 var2 var3 sazae 11 12 13 masuo 21 22 23 tarachan 31 32 33
Dat03 score dat03 var1 var2 var3 Name Conditionn, var1, var2, var3 > dat04 score name condition 1 11 sazae var1 > dat03 2 21 masuo var2 var1 var2 var3 3 31 tarachan var3 sazae 11 12 13 4 12 sazae var1 masuo 21 22 23 5 22 masuo var2 6 32 tarachan var3 tarachan 31 32 33 7 13 sazae var1 8 23 masuo var2 9 33 tarachan var3
score var1 var2 var3 Name Conditionn, var1, var2, var3 > dat04<-data.frame(score=c(dat03$var1,dat03$var2,dat03$var3), name=rep(rownames(dat03),3), condition = rep(c("var1","var2","var3"),3))
dat<-read.csv("http://www.matsuka.info/data_folder/datwa01.txt", > head(dat) shoesize header=t); h gender 1 27.0 181.4 M 2 26.5 170.8 M 3 27.5 182.3 M 4 26.5 166.8 M 5 23.5 153.2 F 6 23.0 151.6 F > head(dat) shoesize height (meter) gender 1 27.0 1.814 M 2 26.5 1.708 M 3 27.5 1.823 M 4 26.5 1.668 M 5 23.5 1.532 F 6 23.0 1.516 F
mean(dat$shoesize[dat$gender == "M"]) [1] 25.98529 # mean(dat$shoesize[dat$gender == "F"]) [1] 23.72222 # mean(dat$shoesize[dat$h > 180]) [1] 27.5 # 180cm
v1 = seq(-3,3,0.1) v2 = v1^2 > plot(x = v1, y = v2) y 0 2 4 6 8-3 -2-1 0 1 2 3 x col= color > plot(v1, v2, col = 'red') y 0 2 4 6 8-3 -2-1 0 1 2 3 x
marker pch = N > plot(v1, v2, col= red ) > plot(v1, v2, col= red, pch = 20) # N: 0~25 # help(points)
marker cex = N > plot(v1, v2, col= red, pch = 20) > plot(v1, v2, col= red, pch = 20, cex = 3)
1 2 3 4 5 21 22 23 24 25 16 17 18 19 20 11 12 13 14 15 6 7 8 9 10 1 2 3 4 5 1 2 3 4 5
type= style > plot(v1, v2) > plot(v1, v2, type = l ) # style: p:points l:line b:both (points & line) o:overlay (points & line) n:none
lty = N #N: 1~6 lwd = W > plot(v1,v2,type='l',lty=4,lwd=3) y 0 2 4 6 8-3 -2-1 0 1 2 3 x
plot(v1, v2, main = "THIS IS THE TITLE", xlab = "Label for X-axis", ylab = "Label for Y-axis") THIS IS THE TITLE Label for Y-axis 0 2 4 6 8-3 -2-1 0 1 2 3 Label for X-axis
plot(v1, v2, main = "THIS IS THE TITLE", cex.lab = 1.5, xlab = "Label for X-axis",ylab = "Label for Y-axis")
X Y plot(v1, v2, main = "TITLE", xlab = "X here",ylab = "Y here", xlim = c(-3.5, 3.5), TITLE ylim = c(-0.5, 10)) Label for Y-axis 0 2 4 6 8 THIS IS THE TITLE -3-2 -1 0 1 2 3 Y here 0 2 4 6 8 10 Label for X-axis -3-2 -1 0 1 2 3 X here
plot(v1, v2, col = "blue", type = "o", lty = 2, pch = 19, cex.lab = 1.5, lwd = 3, main = "Y=X*X", xlab = "X", ylab="x*x", xlim=c(-3.5,3.5), ylim=c(-0.5, 10))
Histogram > dat<- read.csv("http://www.matsuka.info/data_folder/datwa01.txt") > hist(dat$h)
Histogram > hist(dat$h, breaks = 20, main = Histogram of Height, xlab = "Height", col = 'blue', xlim = c(140, 190))
dens<-density(dat$h); # hist(dat$h, main = "Histogram of Height", xlab = "Height", xlim = c(140,190), probability = T) lines(dens, lwd = 2, col = red, lty=2) # Histogram of Height Density 0.00 0.01 0.02 0.03 0.04 140 150 160 170 180 190 Height
#lines plot(v1, v2, col = "blue", type = "l", pch = 19, cex.lab = 1.5, lwd = 3, xlab = "X", ylab="f(x)", xlim=c(-3.5,3.5), ylim=c(-0.5, 10)) lines(v1, v1^3, col='red',lwd = 3)
#legend legend("bottomright", c("x^2","x^3"), col=c('blue','red'), lwd=2)
> boxplot(dat$h,main="boxplot of Height", ylab="height", col='cyan', ylim=c(140,190)) > boxplot(dat$h,main="boxplot of Height", xlab="height", col= ornage', horizontal=t) Boxplot of Height Height 140 150 160 170 180 190
http://www.stat.columbia.edu/~tzheng/files/rcolor.pdf
boxplot(dat$h ~ dat$gender, main="distribution of Height by Gender", ylab="gender", xlab="height", col=c('blue','cyan'), ylim=c(140,190), horizontal=t) Distribution of Height by Gender Gender F M 140 150 160 170 180 190
dat<-read.table("http://www.matsuka.info/data_folder/aov01.txt") boxplot(dat$h ~ dat$gender + dat$affil, main="distribution of Height by Gender and Affiliation", ylab="gender x Affiliation", xlab="height", col=c('blue,'cyan,'red,'magenta'), ylim=c(140,190),horizontal=t) Distribution of Height by Gender and Affiliation Gender x Affiliation F.cs M.cs F.psy M.psy 140 150 160 170 180 190 Height
interaction.plot(dat$gender, dat$affil, dat$h, Y pch=c(20,20), col=c("skyblue","orange"), xlab="gender", ylab= height", lwd=3,type='b',cex=2, trace.label="affiliation") Legend X
Distribution of Height by Gender and Affiliation Gender x Affiliation F.cs M.cs F.psy M.psy 140 150 160 170 180 190 Height
HISTOGRAM par(mfrow=c(1,2)) # figure Dist. of Height for Female Participants Dist. of Height for Male Participants Density 0.00 0.02 0.04 0.06 0.08 Density 0.00 0.02 0.04 0.06 0.08 140 150 160 170 180 190 Height 140 150 160 170 180 190 Height
HISTOGRAM hist(dat[dat$gender=='f',]$h, main="dist. of Height for Female Participants", xlab="height", xlim=c(140,190), probability=t) dens.f = density(dat[dat$gender=='f',]$h) lines(dens.f, col='blue',lwd=2) hist(dat[dat$gender== M,]$h, main= Dist. of Height for Male Participants, xlab= Height, xlim=c(140,190), probability=t,ylim=c(0,0.08)) dens.m = density(dat[dat$gender=='m',]$h) lines(dens.m, col='green', lwd=2)
HISTOGRAM Dist. of Height for Female Participants Dist. of Height for Male Participants Density 0.00 0.02 0.04 0.06 0.08 Density 0.00 0.02 0.04 0.06 0.08 140 150 160 170 180 190 Height 140 150 160 170 180 190 Height
par(mfrow=c(1,1)) plot(dens.f,col='blue',lwd=2, ylab='density', xlim=c(140,190), main="dist. of Height by gender",xlab='height') lines(dens.m,col='green',lwd=2) legend("topleft", c('female','male'), col=c('blue','green'), cex=1.5,lwd=2)
# text(x,y, TEXT ) text(157.5, 0.04, 'Female', col='blue', cex=2) text(170, 0.04,'Male', col='green', cex=2) Dist. of Height by gender density 0.00 0.02 0.04 0.06 Female Male 140 150 160 170 180 190 Height
21 22 23 24 25 1 2 3 4 5 16 17 18 19 20 11 12 13 14 15 6 7 8 9 10 1 2 3 4 5 1 2 3 4 5
# plot(x,y, ) plot(dat$shoesize, dat$h, main="relationship b/w shoesize and height, xlab = 'shoesize, ylab='height, pch=19, col='red ) Relationship b/w shoesize and height height 150 160 170 180 21 22 23 24 25 26 27 28 shoesize
txt = paste("r =",round(cor(dat$shoesize,dat$h), 4)) > txt[1] "r = 0.875" a=1:3 paste("s",a) => [1] "s 1" "s 2" "s 3" paste( s, a, sep= ) => [1] "s1" "s2" "s3"
txt = paste("r =", round(cor(dat$shoesize,dat$h), 4)) text(22, 175, txt, cex = 1.5) Relationship b/w shoesize and height height 150 160 170 180 r = 0.874 21 22 23 24 25 26 27 28 shoesize
abline: abline(h = mean(dat$h), col='blue'); abline(v = mean(dat$shoesize), col='green'); Relationship b/w shoesize and height H V height 150 160 170 180 r = 0.874 mean height mean shoesize 21 22 23 24 25 26 27 28 shoesize
abline(lm(dat$h~dat$shoesize), lty=2, lwd=2) Relationship b/w shoesize and height height 150 160 170 180 r = 0.874 21 22 23 24 25 26 27 28 shoesize
plot(dat[dat$gender=='f',]$shoesize, dat[dat$gender=='f',]$h, main="relationship b/w shoesize and height", xlab='shoesize', ylab='height', cex.lab=1.5, pch=19, col='blue', xlim=c(20,29), ylim=c(140,190)) Relationship b/w shoesize and height height 140 150 160 170 180 190 Female Male 20 22 24 26 28 shoesize
lines(dat[dat$gender=='m',]$shoesize,dat[dat$gender=='m',]$h, type = 'p', pch = 15, col = 'green') legend("topleft", c('female','male'), pch =c(19,15), col = c('blue','green'), cex = 1.5) height 140 150 160 170 180 190 Female Male Relationship b/w shoesize and height 20 22 24 26 28 shoesize
plot(dat.reg, pch=20, col=c('blue')) 100 140 180 50 100 150 200 material 2 4 6 8 10 100 140 180 price design 10 30 50 70 50 100 150 200 sales 2 4 6 8 10 10 20 30 40 50 60 70
plot(dat.pca, pch = rownames(dat.pca), cex = 1.7, col = 'blue') writing 40 50 60 70 80 90 a b c d e f g h i 40 50 60 70 80 90 a b c d e f g h i 40 50 60 70 80 90 a b c d e f g h i thesis a b c d e f g h i 40 50 60 70 80 90 a b c d e f g h i a b c d e f g h i 40 50 60 70 80 90 40 50 60 70 80 90 interview