Today
강의
R 프로그램, 통계 25강 까지
스터디 내용
24. plot option, type
x <- c(1:10)
y <- x^2 - x + 10
plot(x, y, type ="n") # type = n : 아무것도 출력하지 마라, b : 선, 점 들어감, p : 디폴트 값, s|S : 계단식 모형, h : 선이 값 아래로 그려짐
plot(x, y, type ="p", col = "blue", pch = 2)
par(mfrow=c(2,4)) # 2 * 4 총 8개 그래프 한 번에 그려주는 옵션
for(i in 9:16){plot(x, y, type ="p", col = "blue", pch = i)}
par(mfrow=c(2,4))
types = c("p", "l", "o", "b", "c", "s", "S", "h")
for(i in 1:8){
plot(x, y, type = types[i], col = "blue", pch = i)
}
25. if 구문, 조건문
use : if(condition) {do1} else if {do2} else
mtcars
aggregate(mtcars$mpg, by = list(mtcars$cyl), mean)
mean_by_cyl <- function(x) {
if(X == 4) { a <- round(mean(mtcars[which(mtcars$cyl == 4),][,1]),2)
return(paste('The avg mile per gallon of', x, 'cylinder car is', a))}
else if(x == 6) {
round(mean(mtcars[which(mtcars$cyl == 6),][,1]),2)
return(paste('The avg mile per gallon of', x, 'cylinder car is', b))}
else if(x == 8) {
round(mean(mtcars[which(mtcars$cyl == 8),][,1]),2)
return(paste('The avg mile per gallon of', x, 'cylinder car is', c))}
else { print('Wrong number!!')}
}
mean_by_cyl(8)
mean_by_cyl(4)
mean_by_cyl2 <- function(x) { mean(mtcars[which(mtcars$cyl == x),][,1])}
mean_by_cyl2(4)
Result
Tomorrow
- 매일 1시간 정도 R 강의 수강 및 실습 진행
Summary