R Basic Code
R Basic Code
Vector ####
c(1,2,3)
c("a","hellow","b")
c(1,-1,"a")
c(1:10)
seq(from=1,to=5,by=0.5)
rep(x=5,time=3)
pi # pi
exp(2) # exponential
max(x)
min(x)
sum(x)
mean(x)
median(x)
range(x)
sort(x)
# function1 : y = k+1
my_fun <- function(k){
y = k+1
return(y)
}
my_fun(k=3)
# numeric
12
class(12)
# character
"a"
class("a")
"12"
class("12")
a <- c(1,2,"b")
class(a)
A_mat[1,1]
A_mat[,1]
A_mat[1,]
A_mat+2
A_mat*2
A_mat + B_mat
A_mat - B_mat
A_mat*B_mat
A_mat/B_mat
A_mat%*%B_mat
matrix(c("2",1,2,3),ncol=2,byrow=F)
dat[,1]
dat$c1
dat[1,]
dat[,-1]
dat[-1,]
#### 7. Graphic ####
cars
names(cars)
dim(cars)
head(cars)
cars$speed
cars$dist
plot(x=cars$speed,y=cars$dist)
plot(x=cars$speed,y=cars$dist,cex=3)
plot(x=cars$speed,y=cars$dist,cex=2,pch=16,col="red")
plot(x=cars$speed,y=cars$dist,cex=2,pch=16,col="red",cex.lab=1.5,xlab="Speed(x)",yl
ab="Dist(y)")
plot(x=cars$speed,y=cars$dist,cex=2,pch=16,col="red",cex.lab=1,xlab="Speed(x)",ylab
="Dist(y)"
,main="The realtionship of Dist and Speed")