티스토리 뷰
INTRO
1. 벡터형 변수
2. 행렬/데이터프레임
test_indexing.R
rm(list = ls())
setwd("/Users/[YourMacID]/Rcoding")
a_chr = c('a', 'b', 'c', 'd', 'e')
## vector indexing
a_chr[1]
a_chr[-1]
a_chr[c(2,4)]
a_chr[1:3]
## dataframe indexing
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)
mydat[3,2]
mydat[,2]
mydat[3,]
출력결과
> source("~/Rcoding/test_indexing.R", echo=TRUE)
> rm(list = ls())
> setwd("/Users/[YourMacID]/Rcoding")
> a_chr = c('a', 'b', 'c', 'd', 'e')
> ## vector indexing
> a_chr[1]
[1] "a"
> a_chr[-1]
[1] "b" "c" "d" "e"
> a_chr[c(2,4)]
[1] "b" "d"
> a_chr[1:3]
[1] "a" "b" "c"
> ## dataframe indexing
> 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
> mydat[3,2]
[1] "kia"
> mydat[,2]
[1] "kia" "hyundai" "kia" "toyota" "lexus"
> mydat[3,]
income car marriage
3 150 kia FALSE
반응형
'R' 카테고리의 다른 글
(macOS)[R] paste, substr, as., date, format (0) | 2022.03.28 |
---|---|
(macOS)[R] 반복문 : for, while | 조건문 : if/else | 사용자 정의 함수 : function() (0) | 2022.03.28 |
(macOS)[R] 기초함수, 수치계산 (0) | 2022.03.28 |
(macOS)[R] file import : csv, txt, xls, xlsx (0) | 2022.03.15 |
(macOS)[R] data structure : vector, matrix, dataframe (0) | 2022.03.14 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- COVID-19
- raspberrypi
- pyserial
- Templates
- Regression
- DAQ
- ERP
- server
- 코로나19
- 라즈베리파이
- github
- sublime text
- analysis
- git
- r
- vscode
- template
- Pandas
- Raspberry Pi
- arduino
- MacOS
- 확진
- Python
- 자가격리
- DS18B20
- SSH
- Model
- CSV
- 코로나
- Django
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함