라일락 꽃이 피는 날

[R] 데이터 프레임 (Data Frame) 본문

데이터 분석/R

[R] 데이터 프레임 (Data Frame)

eunki 2021. 6. 19. 18:34
728x90

데이터 프레임 (Data Frame)

가장 일반적인 데이터 형태로, 행(Row)과 열(Column)의 조합이다.

행이 많을수록 고사양 장비가 필요하고, 열이 많을수록 고급 분석방법을 사용해야 한다.

 

 

 

1. 데이터 프레임 만들기

데이터 프레임명 <- data.frame(변수1, 변수2, ···)

history <- c(90, 80, 60, 70)
math <- c(50, 60, 100, 20) 

df_midterm <- data.frame(history, math) 
df_midterm 
'''
  history math
1      90   50
2      80   60
3      60  100
4      70   20
'''

 



2. 열(Column) 추가하기

class_ <- c(1, 1, 2, 2) 

df_midterm <- data.frame(history, math, class_) 
df_midterm
'''
  history math class_
1      90   50     1
2      80   60     1
3      60  100     2
4      70   20     2
'''

 

 

 

3. 데이터 프레임 형태로 불러오기

as.data.frame(패키지명::데이터명)

mpg <- as.data.frame(ggplot2::mpg)

head(mpg)

728x90

'데이터 분석 > R' 카테고리의 다른 글

[R] 데이터 수정하기  (0) 2021.06.19
[R] 데이터 파악하기  (0) 2021.06.19
[R] 외부 데이터 불러오기  (0) 2021.06.19
[R] 함수 (function), 패키지 (packages)  (0) 2021.06.19
[R] 변수 (Variable)  (0) 2021.06.19