IT grow. 2018. 9. 7. 01:57
반응형
x<- seq (1,10,by=3)
# 1 ~ +3 , 10
y<-seq(1,10,length.out=5)
# 1~10 same length five number
x<-c(1,2,3)
rep(x,times=2)
# repeat : times : All element x 2
rep(x,each=2)
#repeat : each : element x 2
x<- c(1,2,3,4,5)
x[2]
# element 2
x[c(1,3,5)]
# element 1,3,5
x[-c(2,4)]
# remove element 2,4
x[x>2]
# greater than 2
x[x>2 & x <4]
# greater than 2 and less than 4
x[2] <- 20
# x[2] input 20
x[c(3,4)] <-15
# each element x[3],x[4] input 15
x[x<=15] <- 10
# less than 15 elements to 10
x<- seq(1,10)
mean(x)
# Average (x)
var(x)
# Dispersion(x)
sd(x)
# standard Deviation(x)
sqrt(x)
# square root(x)
length(x)
# amount
abs(x)
#Absolute Value
x<- array(1:3,dim=c(3))
# same = x <- seq(1:3)
x<- array(1:6,dim=c(2,3))
# x1차 배열 생성 , 2행 3열 , 1~6 숫자
x[1,3]
x[,3]
x[,-3]
x[1,2] <-20
x<-matrix(1:9 , nrow=3)
# 1~9 정수 , 행의 숫자가 3개인
v1<-c(1,2,3,4)
v2<-c(5,6,7,8)
v3<-c(9,10,11,12)
x<-cbind(v1,v2,v3)
# Column bind , 열 단위로 합침
y <- rbind(v1,v2,v3)
# Row bind , 행 단위로 합침
x<-data.frame(성명=c("홍길동","손오공"),나이=c(20,30),주소=c("서울","부산"))
quakes
# dataset
head(quakes, n=10) # 데이터 앞부분 10개 행
tail(quakes , n=6) # 데이터 뒷부분 6개 행 보기
names(quakes) # quakes의 변수명 보기
str(quakes) # 데이터 구조 보기
dim(quakes) # 행과 열의 수
summary(quakes) # 변수별 데이터 요약 정보
summary(quakes $ mag) # mag 변수에 대한 최솟값 ..... 최댓값
write.table(quakes,"C:/Users/user/Documents/R/quakes.txt",sep=",")
# R 하위 폴더내에 quakes의 txt 저장 , 데이터 간의 구분자는 , 로
x<- read.csv("C:/Users/user/Documents/R/quakes.txt",header = T)
#header=T는 데이터 파일의 첫 번째 행믁 항목명으로 인식
PieMultiple <-function(r)
{
area = 3.14 * r ^ 2
return(area)
}
# 함수 적용 가능


반응형