260220 study
This commit is contained in:
@@ -1,27 +0,0 @@
|
||||
{
|
||||
"id": "FEFD8679",
|
||||
"path": "~/R project/r_study/기초 명령어 실습.R",
|
||||
"project_path": "기초 명령어 실습.R",
|
||||
"type": "r_source",
|
||||
"hash": "3000786226",
|
||||
"contents": "",
|
||||
"dirty": false,
|
||||
"created": 1769651679182.0,
|
||||
"source_on_save": false,
|
||||
"relative_order": 1,
|
||||
"properties": {
|
||||
"tempName": "Untitled1",
|
||||
"source_window_id": "",
|
||||
"Source": "Source",
|
||||
"cursorPosition": "154,0",
|
||||
"scrollLine": "141"
|
||||
},
|
||||
"folds": "",
|
||||
"lastKnownWriteTime": 1771481370,
|
||||
"encoding": "UTF-8",
|
||||
"collab_server": "",
|
||||
"source_window": "",
|
||||
"last_content_update": 1771481370916,
|
||||
"read_only": false,
|
||||
"read_only_alternatives": []
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
## 기초 명령어 실습 ##
|
||||
|
||||
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)
|
||||
@@ -0,0 +1,4 @@
|
||||
.Rproj.user
|
||||
.Rhistory
|
||||
.RData
|
||||
.Ruserdata
|
||||
Binary file not shown.
@@ -0,0 +1,4 @@
|
||||
id gender bt age
|
||||
1 남자 A 23
|
||||
2 여자 B 21
|
||||
3 남자 A 34
|
||||
@@ -0,0 +1,5 @@
|
||||
id,height,weight
|
||||
1,175,70
|
||||
2,167,58
|
||||
3,178,82
|
||||
4,162,45
|
||||
@@ -0,0 +1,5 @@
|
||||
id major grade
|
||||
1 생물학 3
|
||||
2 경영학 2
|
||||
3 통계학 4
|
||||
4 컴퓨터공학 2
|
||||
@@ -0,0 +1,3 @@
|
||||
## read text data ##
|
||||
k200 = read.csv(file = './data/k100.csv',header = TRUE)
|
||||
k200
|
||||
Reference in New Issue
Block a user