티스토리 뷰
INTRO
1. 백터 : vector
2. 행렬 : matrix
3. 데이터 프레임 : dataframe
1. Vector
- 하나 이상의 스칼라 원소들을 갖는 집합
- 숫자, 문자, 논리 연산자 등
- 'c'(concentration, 연결)를 통해 선언
2. Matrix
- m(행,row) x n(열,col) 형태 데이터 구조
3. DataFrame
- R에서 가장 널리 사용
- 2차원 목록 데이터 구조
test_data.R
## vector by c
x1 = c(1,10,24,40)
y1 = c("사과", "바나나", "오렌지")
z1 = c(TRUE, FALSE, TRUE)
x2 <- c(1,10,24,40)
y2 <- c("사과", "바나나", "오렌지")
z2 <- c(TRUE, FALSE, TRUE)
## vector combine
xy1 <- c(x2, y2)
## matrix
mx1 = matrix(c(1,2,3,4,5,6), ncol=2)
mx2 = matrix(c(1,2,3,4,5,6), ncol=2, byrow=T) #ncol but row first
mx3 = matrix(c(1,2,3,4,5,6), nrow=2)
## matrix ncol, nrow print
print(mx1)
print(mx2)
print(mx3)
## matrix combine rbind, cbind
r1 = c(10,20)
c1 = c(10,20,30)
print(rbind(mx1,r1))
print(cbind(mx1,c1))
## dataframe 2-dimesion data
income = c(100,200,150,300,900)
car = c("kia","hyundai","kia","toyota","lexus")
marriage = c(FALSE,FALSE,FALSE,TRUE,TRUE)
mydat = data.frame(income,car,marriage)
print(mydat)
출력결과 : command+shift+Enter
> ## vector by c
> x1 = c(1,10,24,40)
> y1 = c("사과", "바나나", "오렌지")
> z1 = c(TRUE, FALSE, TRUE)
> x2 <- c(1,10,24,40)
> y2 <- c("사과", "바나나", "오렌지")
> z2 <- c(TRUE, FALSE, TRUE)
> ## vector combine
> xy1 <- c(x2, y2)
> ## matrix
> mx1 = matrix(c(1,2,3,4,5,6), ncol=2)
> mx2 = matrix(c(1,2,3,4,5,6), ncol=2, byrow=T) #ncol but row first
> mx3 = matrix(c(1,2,3,4,5,6), nrow=2)
> ## matrix ncol, nrow print
> print(mx1)
[,1] [,2]
[1,] 1 4
[2,] 2 5
[3,] 3 6
> print(mx2)
[,1] [,2]
[1,] 1 2
[2,] 3 4
[3,] 5 6
> print(mx3)
[,1] [,2] [,3]
[1,] 1 3 5
[2,] 2 4 6
> ## matrix combine rbind, cbind
> r1 = c(10,20)
> c1 = c(10,20,30)
> print(rbind(mx1,r1))
[,1] [,2]
1 4
2 5
3 6
r1 10 20
> print(cbind(mx1,c1))
c1
[1,] 1 4 10
[2,] 2 5 20
[3,] 3 6 30
> ## dataframe 2-dimesion data
> income = c(100,200,150,300,900)
> car = c("kia","hyundai","kia","toyota","lexus")
> marriage = c(FALSE,FALSE,FALSE,TRUE,TRUE)
> mydat = data.frame(income,car,marriage)
> print(mydat)
income car marriage
1 100 kia FALSE
2 200 hyundai FALSE
3 150 kia FALSE
4 300 toyota TRUE
5 900 lexus TRUE
반응형
'R' 카테고리의 다른 글
(macOS)[R] 반복문 : for, while | 조건문 : if/else | 사용자 정의 함수 : function() (0) | 2022.03.28 |
---|---|
(macOS)[R] 데이터 다루기(data handle) (0) | 2022.03.28 |
(macOS)[R] 기초함수, 수치계산 (0) | 2022.03.28 |
(macOS)[R] file import : csv, txt, xls, xlsx (0) | 2022.03.15 |
(macOS)[R] INTRO & Install (0) | 2022.03.10 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- vscode
- 코로나19
- 코로나
- 라즈베리파이
- Regression
- 자가격리
- Python
- CSV
- DS18B20
- analysis
- pyserial
- ERP
- SSH
- DAQ
- Django
- Templates
- arduino
- server
- sublime text
- Raspberry Pi
- MacOS
- COVID-19
- r
- raspberrypi
- github
- 확진
- git
- template
- Pandas
- Model
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
글 보관함