-
-
Save dialektike/afbee0a9f9bedfe0b6a9 to your computer and use it in GitHub Desktop.
엑셀(Excel)의 VLOOKUP 함수 기능을 R에서도 구현해보자!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> a <-c(100,200,300,400,500) | |
> a | |
[1] 100 200 300 400 500 | |
> b <- c("컴퓨터","DSLR","냉장고","TV","에어컨") | |
> b | |
[1] "컴퓨터" "DSLR" "냉장고" "TV" "에어컨" | |
> c <- c(700000,450000,2300000,4100000,1400000) | |
> c | |
[1] 700000 450000 2300000 4100000 1400000 | |
> items <- data.frame(번호=a, 상품명=b, 단가=c) | |
> items | |
번호 상품명 단가 | |
1 100 컴퓨터 700000 | |
2 200 DSLR 450000 | |
3 300 냉장고 2300000 | |
4 400 TV 4100000 | |
5 500 에어컨 1400000 | |
> orderNumbers <- data.frame(번호=c(200,100,500)) | |
> orderNumbers | |
번호 | |
1 200 | |
2 100 | |
3 500 | |
> Order <- merge(items, orderNumbers, by.x="번호", by.y="번호") | |
> Order | |
번호 상품명 단가 | |
1 100 컴퓨터 700000 | |
2 200 DSLR 450000 | |
3 500 에어컨 1400000 | |
> Order$수량 <-c(1,3,1) | |
> Order$금액 <- (Order$단가 * Order$수량) | |
> Order | |
번호 상품명 단가 수량 금액 | |
1 100 컴퓨터 700000 1 700000 | |
2 200 DSLR 450000 3 1350000 | |
3 500 에어컨 1400000 1 1400000 | |
> sum(Order$금액) | |
[1] 3450000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment