260220 study
This commit is contained in:
@@ -1,38 +1,3 @@
|
||||
install.packages(c("mgcv", "survival"))
|
||||
a <- 7
|
||||
cls
|
||||
## 기초 명령어 실습 ##
|
||||
## 기초 명령어 실습 ##
|
||||
1+1
|
||||
1:10
|
||||
dd = c(1:10)
|
||||
dd
|
||||
dd [2:3,]
|
||||
dd [c(2:3),]
|
||||
dd [2:3]
|
||||
dd[2:3]
|
||||
dd[1:9]
|
||||
dd[-1]
|
||||
dd[-10]
|
||||
dd[-10]
|
||||
detach("package:base", unload = TRUE)
|
||||
install.packages("foreign")
|
||||
x1 = 3
|
||||
x2 = "Love is choice"
|
||||
x3 = FALSE
|
||||
x4 = 3-2i
|
||||
str(x1)
|
||||
str(x2)
|
||||
str(x3)
|
||||
str(x4)
|
||||
str(x1,x2,x3,x4)
|
||||
4
|
||||
str(x4)
|
||||
str(x5)
|
||||
str(x5)
|
||||
x5 = '123'
|
||||
str(x5)
|
||||
str(x1)
|
||||
str(x3)
|
||||
str(x7)
|
||||
x7 = 'FLASE'
|
||||
@@ -236,3 +201,312 @@ str(DF4)
|
||||
install.packages('psych')
|
||||
library(psych)
|
||||
describe(DF4)
|
||||
## 기초 명령어 실습 ##
|
||||
1+1
|
||||
1:10
|
||||
dd = c(1:10)
|
||||
## c() -> 같은 종류의 요소(numeric, int, float등)만 있을때
|
||||
## list() -> 다양한 종류의 요소가 들어올때
|
||||
dd[-10]
|
||||
## 기본유형 ##
|
||||
x1 = 3 # numeric
|
||||
x2 = "Love is choice" # character
|
||||
x3 = FALSE # logical
|
||||
x4 = 3-2i # complex
|
||||
x5 = '123' # character
|
||||
x6 = 'false' # character
|
||||
x7 = 'FLASE' # character
|
||||
str(x1)
|
||||
### 문자 - 정수 - 논리
|
||||
### 결측값은 95%까지
|
||||
### 정규분포는 30번이상한것으로 해야한다
|
||||
xx1 <- c(1:100)
|
||||
xx1
|
||||
is.na(xx1)
|
||||
table(is.na(xx1))
|
||||
x1 = c(1,'love',TRUE,2+3i)
|
||||
x1
|
||||
v1 = c(27,35,47,41)
|
||||
mode(v1)
|
||||
is.numeric(v1)
|
||||
is.na(v1)
|
||||
table(is.na(v1))
|
||||
v2 = c(27,35,47,NA,55)
|
||||
mode(v2)
|
||||
is.numeric(v2)
|
||||
is.na(v2)
|
||||
table(is.na(v2))
|
||||
length(v1)
|
||||
length(v2)
|
||||
names(v1)
|
||||
names(v1) = c('kim','lee','park','choi')
|
||||
names(v1)
|
||||
## Indexing ## 대괄호 == [ ] => 추출해라
|
||||
v1
|
||||
v1[1]
|
||||
v1[1:3]
|
||||
v1[-4]
|
||||
v1[c(2,4)]
|
||||
v1 = 1:3
|
||||
v2 = 4:6
|
||||
v3 = v1+v2 # can add list
|
||||
v1 = 1:3
|
||||
v2 = 1:6
|
||||
v3 = v1+v2 # reusable add
|
||||
v3
|
||||
### 데이터거래사
|
||||
## Factor, ordered Factor (등급을 정할 수 있는)
|
||||
gender = c('m','f','f','m','f','f')
|
||||
gender_factor = factor(gender)
|
||||
levels(gender_factor)
|
||||
gender_factor2 = factor(gender, levels = c('m','f'), labels = c('남자','여자'))
|
||||
gender_factor2
|
||||
gender_factor3 = factor(gender,ordered = TRUE)
|
||||
gender_factor3
|
||||
## Matrix ##
|
||||
v1 = 1:3
|
||||
v2 = 4:6
|
||||
m1 = rbind(v1,v2)
|
||||
m2 = cbind(v1,v2)
|
||||
v1
|
||||
v2
|
||||
m1
|
||||
m2
|
||||
m1[2,1] == 8
|
||||
m1[2,1] = 8
|
||||
m1[,3]
|
||||
is.na(m1)
|
||||
table(is.na(m1))
|
||||
m1[1,1] = NA
|
||||
m1[2,3] = NA
|
||||
table(is.na(m1))
|
||||
str(m1)
|
||||
m3 = matrix(1:4, nrow = 2, ncol = 2)
|
||||
m4 = matrix(1:4, nrow = 2, ncol = 2, byrow = TRUE)
|
||||
m3
|
||||
m4[2,1] = NA
|
||||
## array ##
|
||||
a1 = array(1:10, dim=10)
|
||||
a2 = array(1:10, dim=c(2, 5))
|
||||
a3 = array(1:10, dim=c(3, 3, 4))
|
||||
a1
|
||||
a2
|
||||
a3[,,2][3,3] = 100
|
||||
a3
|
||||
## DataFrame ##
|
||||
id = 1:5
|
||||
age = c(29, 32, 47, 35, 23)
|
||||
gender = c('f','m','m','f','f')
|
||||
height = c(163, 177, 172, 157, 169)
|
||||
DF1 = data.frame(id, age, gender, height)
|
||||
DF2 = data.frame(id, age, gender, height, stringsAsFactors=FALSE)
|
||||
DF3 = data.frame(id, age, gender, height, stringsAsFactors=TRUE)
|
||||
DF1
|
||||
DF2
|
||||
DF3
|
||||
View(DF3)
|
||||
str(DF3)
|
||||
DF4 = DF3[-1]
|
||||
DF4
|
||||
View(DF4)
|
||||
str(DF4)
|
||||
## 기술통계량 ##
|
||||
library('psych')
|
||||
describe(DF4)
|
||||
rownames(DF1)
|
||||
colnames(DF1)
|
||||
rownames(DF1) = paste('R',1:5,sep='')
|
||||
rownames(DF1)
|
||||
rownames(DF1) = paste('Edge',1:5,sep='')
|
||||
rownames(DF1)
|
||||
rownames(DF1) = paste('Edge',1:5,sep='_')
|
||||
rownames(DF1)
|
||||
View(DF1)
|
||||
colnames(DF1) = paste(c('id','나이','성별','키'))
|
||||
colnames(DF1)
|
||||
colnames(DF1) = paste('id','나이','성별','키')
|
||||
colnames(DF1)
|
||||
colnames(DF1) = paste(c('id','나이','성별','키'))
|
||||
colnames(DF1) = paste(c('아이디','나이','성별','키'))
|
||||
colnames(DF1)
|
||||
str(DF1)
|
||||
str(DF4)
|
||||
dim(DF1)
|
||||
install.packages("caret")
|
||||
## 기술통계량 ##
|
||||
library(psych)
|
||||
describe(DF4)
|
||||
search()
|
||||
searchpaths()
|
||||
## read text data ##
|
||||
k200 = read.csv(file = './data/k100.csv',header = TRUE)
|
||||
k200
|
||||
## 기초 명령어 실습 ##
|
||||
1+1
|
||||
1:10
|
||||
dd = c(1:10)
|
||||
## c() -> 같은 종류의 요소(numeric, int, float등)만 있을때
|
||||
## list() -> 다양한 종류의 요소가 들어올때
|
||||
dd[-10]
|
||||
## 기본유형 ##
|
||||
x1 = 3 # numeric
|
||||
x2 = "Love is choice" # character
|
||||
x3 = FALSE # logical
|
||||
x4 = 3-2i # complex
|
||||
x5 = '123' # character
|
||||
x6 = 'false' # character
|
||||
x7 = 'FLASE' # character
|
||||
str(x1)
|
||||
### 문자 - 정수 - 논리
|
||||
### 결측값은 95%까지
|
||||
### 정규분포는 30번이상한것으로 해야한다
|
||||
xx1 <- c(1:100)
|
||||
xx1
|
||||
is.na(xx1)
|
||||
table(is.na(xx1))
|
||||
x1 = c(1,'love',TRUE,2+3i)
|
||||
x1
|
||||
v1 = c(27,35,47,41)
|
||||
mode(v1)
|
||||
is.numeric(v1)
|
||||
is.na(v1)
|
||||
table(is.na(v1))
|
||||
v2 = c(27,35,47,NA,55)
|
||||
mode(v2)
|
||||
is.numeric(v2)
|
||||
is.na(v2)
|
||||
table(is.na(v2))
|
||||
length(v1)
|
||||
length(v2)
|
||||
names(v1)
|
||||
names(v1) = c('kim','lee','park','choi')
|
||||
names(v1)
|
||||
## Indexing ## 대괄호 == [ ] => 추출해라
|
||||
v1
|
||||
v1[1]
|
||||
v1[1:3]
|
||||
v1[-4]
|
||||
v1[c(2,4)]
|
||||
v1 = 1:3
|
||||
v2 = 4:6
|
||||
v3 = v1+v2 # can add list
|
||||
v1 = 1:3
|
||||
v2 = 1:6
|
||||
v3 = v1+v2 # reusable add
|
||||
v3
|
||||
### 데이터거래사
|
||||
## Factor, ordered Factor (등급을 정할 수 있는)
|
||||
gender = c('m','f','f','m','f','f')
|
||||
gender_factor = factor(gender)
|
||||
levels(gender_factor)
|
||||
gender_factor2 = factor(gender, levels = c('m','f'), labels = c('남자','여자'))
|
||||
gender_factor2
|
||||
gender_factor3 = factor(gender,ordered = TRUE)
|
||||
gender_factor3
|
||||
## Matrix ##
|
||||
v1 = 1:3
|
||||
v2 = 4:6
|
||||
m1 = rbind(v1,v2)
|
||||
m2 = cbind(v1,v2)
|
||||
v1
|
||||
v2
|
||||
m1
|
||||
m2
|
||||
m1[2,1] == 8
|
||||
m1[2,1] = 8
|
||||
m1[,3]
|
||||
is.na(m1)
|
||||
table(is.na(m1))
|
||||
m1[1,1] = NA
|
||||
m1[2,3] = NA
|
||||
table(is.na(m1))
|
||||
str(m1)
|
||||
m3 = matrix(1:4, nrow = 2, ncol = 2)
|
||||
m4 = matrix(1:4, nrow = 2, ncol = 2, byrow = TRUE)
|
||||
m3
|
||||
m4[2,1] = NA
|
||||
## array ##
|
||||
a1 = array(1:10, dim=10)
|
||||
a2 = array(1:10, dim=c(2, 5))
|
||||
a3 = array(1:10, dim=c(3, 3, 4))
|
||||
a1
|
||||
a2
|
||||
a3[,,2][3,3] = 100
|
||||
a3
|
||||
## DataFrame ##
|
||||
id = 1:5
|
||||
age = c(29, 32, 47, 35, 23)
|
||||
gender = c('f','m','m','f','f')
|
||||
height = c(163, 177, 172, 157, 169)
|
||||
DF1 = data.frame(id, age, gender, height)
|
||||
DF2 = data.frame(id, age, gender, height, stringsAsFactors=FALSE)
|
||||
DF3 = data.frame(id, age, gender, height, stringsAsFactors=TRUE)
|
||||
DF1
|
||||
DF2
|
||||
DF3
|
||||
View(DF3)
|
||||
str(DF3)
|
||||
DF4 = DF3[-1]
|
||||
DF4
|
||||
View(DF4)
|
||||
str(DF4)
|
||||
## 기술통계량 ##
|
||||
library(psych)
|
||||
describe(DF4)
|
||||
rownames(DF1) = paste('Edge',1:5,sep='_')
|
||||
rownames(DF1)
|
||||
colnames(DF1) = paste(c('아이디','나이','성별','키'))
|
||||
colnames(DF1)
|
||||
dim(DF1)
|
||||
searchpaths()
|
||||
## read text data ##
|
||||
k200 = read.csv(file = './data/k100.csv',header = TRUE)
|
||||
k200
|
||||
View(k200)
|
||||
k300 = read.csv(file = './data/ebook.csv',header = TRUE)
|
||||
View(k300)
|
||||
tsv100 = read.table(file = './data/survey_tab.txt', header = TRUE, encoding = 'CP949')
|
||||
tsv100 = read.table(file = './data/survey_tab.txt', header = TRUE, fileEncoding = 'CP949')
|
||||
View(tsv100)
|
||||
## data handling ##
|
||||
library(ggplot2)
|
||||
head(diamonds)
|
||||
head(Titanic)
|
||||
View(diamonds)
|
||||
View(Titanic)
|
||||
## data structure ##
|
||||
str(diamonds)
|
||||
str(Titanic)
|
||||
View(diamonds)
|
||||
head(diamonds)
|
||||
## indexing ##
|
||||
diamonds[ , 2]
|
||||
diamonds[ , 2, drop=FALSE]
|
||||
diamonds[ , c(2, 3, 7)]
|
||||
diamonds[ , 7:10]
|
||||
diamonds[ , seq(from=2, to=10, by=2)]
|
||||
xx=diamonds[ , c(2, 3, 7)]
|
||||
View(xx)
|
||||
xx
|
||||
ss = diamonds[,7]
|
||||
describe(ss)
|
||||
describe(diamonds)
|
||||
diamonds[ , c('cut', 'price'
|
||||
diamonds[ , 'cut']
|
||||
diamonds[ , 'cut']
|
||||
diamonds[ , c('cut', 'price')]
|
||||
diamonds[diamonds$cut == 'Fair', ]
|
||||
diamonds[diamonds$price >= 18000, ]
|
||||
a
|
||||
a = diamonds[diamonds$cut == 'Fair', ]
|
||||
a
|
||||
table(a)
|
||||
= diamonds[diamonds$price >= 18000, ]
|
||||
b
|
||||
b = diamonds[diamonds$price >= 18000, ]
|
||||
b
|
||||
'Fair') & (diamonds$price >= 18000), ]
|
||||
c = diamonds[(diamonds$cut == 'Fair') & (diamonds$price >= 18000), ]
|
||||
d = diamonds[(diamonds$cut == 'Fair') | (diamonds$price >= 18000), ]
|
||||
View(c)
|
||||
View(d)
|
||||
|
||||
Reference in New Issue
Block a user