260220 study

This commit is contained in:
2026-02-20 15:16:04 +09:00
parent e7ad947aca
commit 1b8a8d2b72
7 changed files with 373 additions and 40 deletions
+309 -35
View File
@@ -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(x3)
str(x7) str(x7)
x7 = 'FLASE' x7 = 'FLASE'
@@ -236,3 +201,312 @@ str(DF4)
install.packages('psych') install.packages('psych')
library(psych) library(psych)
describe(DF4) 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)
+1 -1
View File
@@ -5,5 +5,5 @@
"ascending": true "ascending": true
} }
], ],
"path": "~/R project/r_study" "path": "~/R project/r_study/data"
} }
@@ -1,6 +1,6 @@
{ {
"left": { "left": {
"splitterpos": 433, "splitterpos": 395,
"topwindowstate": "NORMAL", "topwindowstate": "NORMAL",
"panelheight": 1013, "panelheight": 1013,
"windowheight": 1051 "windowheight": 1051
+2 -2
View File
@@ -2,6 +2,6 @@
"tempName": "Untitled1", "tempName": "Untitled1",
"source_window_id": "", "source_window_id": "",
"Source": "Source", "Source": "Source",
"cursorPosition": "154,0", "cursorPosition": "185,54",
"scrollLine": "141" "scrollLine": "172"
} }
+6
View File
@@ -1,4 +1,10 @@
~%2FR%20project%2Fr_study%2F%E1%84%80%E1%85%B5%E1%84%8E%E1%85%A9%20%E1%84%89%E1%85%B5%E1%86%AF%E1%84%89%E1%85%B3%E1%86%B8%20II.R="E78BE5EA"
~%2FR%20project%2Fr_study%2F%EA%B8%B0%EB%AA%85%EB%A0%B9%EC%96%B4%20%EC%8B%A4%EC%8A%B5.R="01128302" ~%2FR%20project%2Fr_study%2F%EA%B8%B0%EB%AA%85%EB%A0%B9%EC%96%B4%20%EC%8B%A4%EC%8A%B5.R="01128302"
~%2FR%20project%2Fr_study%2F%EA%B8%B0%EC%B4%88%20%EB%AA%85%EB%A0%B9%EC%96%B4%20%EC%8B%A4%EC%8A%B5.R="0CB164D0" ~%2FR%20project%2Fr_study%2F%EA%B8%B0%EC%B4%88%20%EB%AA%85%EB%A0%B9%EC%96%B4%20%EC%8B%A4%EC%8A%B5.R="0CB164D0"
~%2FR%20project%2Fr_study%2Fadvance.R="11E47905" ~%2FR%20project%2Fr_study%2Fadvance.R="11E47905"
~%2FR%20project%2Fr_study%2Fbasic.R="B0F755B1" ~%2FR%20project%2Fr_study%2Fbasic.R="B0F755B1"
~%2FR%20project%2Fr_study%2Fdata%2F%E1%84%8B%E1%85%B5%E1%86%AB%E1%84%80%E1%85%AE%E1%84%8C%E1%85%AE%E1%84%90%E1%85%A2%E1%86%A8%E1%84%8E%E1%85%A9%E1%86%BC%E1%84%8C%E1%85%A9%E1%84%89%E1%85%A12015.csv="F4F2A450"
~%2FR%20project%2Fr_study%2Fdata%2Febook.csv="B032A455"
~%2FR%20project%2Fr_study%2Fdata%2Fsurvey_blank.txt="36BC293B"
~%2FR%20project%2Fr_study%2Fdata%2Fsurvey_comma.txt="E84212BF"
~%2FR%20project%2Fr_study%2Fdata%2Fsurvey_tab.txt="36BC2937"
+6
View File
@@ -1,2 +1,8 @@
/Users/dh/R project/r_study/basic.R="38F7B9A1" /Users/dh/R project/r_study/basic.R="38F7B9A1"
/Users/dh/R project/r_study/data/ebook.csv="D6CC5A14"
/Users/dh/R project/r_study/data/survey_blank.txt="38B1159C"
/Users/dh/R project/r_study/data/survey_comma.txt="F11DD8B3"
/Users/dh/R project/r_study/data/survey_tab.txt="2B3FFD48"
/Users/dh/R project/r_study/data/인구주택총조사2015.csv="034CDF16"
/Users/dh/R project/r_study/기초 실습 II.R="83772E57"
/Users/dh/R project/r_study/기초 명령어 실습.R="CF8199EA" /Users/dh/R project/r_study/기초 명령어 실습.R="CF8199EA"
+48 -1
View File
@@ -149,6 +149,53 @@ View(DF4)
str(DF4) str(DF4)
## 기술통계량 ## ## 기술통계량 ##
library('psych') library(psych) # describe()명령어 호출 라이브러리
describe(DF4) 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)
k300 = read.csv(file = './data/ebook.csv',header = TRUE)
tsv100 = read.table(file = './data/survey_tab.txt', header = TRUE, fileEncoding = 'CP949')
## data handling ##
library(ggplot2)
head(diamonds)
View(diamonds)
head(Titanic)
View(Titanic)
## data structure ##
str(diamonds)
str(Titanic)
## indexing ##
diamonds[ , 2]
diamonds[ , 2, drop=FALSE]
xx = diamonds[ , c(2, 3, 7)] # 2,3,7번째 값 추출
ss = diamonds[,7] # 7번째 값 추출
describe(diamonds) # 기술통계량
diamonds[ , 7:10]
diamonds[ , seq(from=2, to=10, by=2)]
diamonds[ , 'cut']
diamonds[ , c('cut', 'price')]
## 행추출하기 ##
a = diamonds[diamonds$cut == 'Fair', ]
a
b = diamonds[diamonds$price >= 18000, ] # 다이아몬드의 가격을 기준으로 추출
b
c = diamonds[(diamonds$cut == 'Fair') & (diamonds$price >= 18000), ]
d = diamonds[(diamonds$cut == 'Fair') | (diamonds$price >= 18000), ]