R기초; 데이터프레임 생성
v1 <- c("A001", "A002", "A003")
v2 <- c("Mouse", "Keyboard", "USB")
v3 <- c(30000, 90000, 50000)
data.frame(v1, v2, v3)
v1 v2 v3
1 A001 Mouse 30000
2 A002 Keyboard 90000
3 A003 USB 50000
data.frame(row.names=v1, v2, v3)
v2 v3
A001 Mouse 30000
A002 Keyboard 90000
A003 USB 50000
product <- data.frame(id=v1, name=v2, price=v3)
product
id name price
1 A001 Mouse 30000
2 A002 Keyboard 90000
3 A003 USB 50000
str(product)
'data.frame': 3 obs. of 3 variables:
$ id : chr "A001" "A002" "A003"
$ name : chr "Mouse" "Keyboard" "USB"
$ price: num 30000 90000 50000
product <- data.frame(id=v1, name=v2, price=v3, stringAsFactors=FALSE)
str(product)
'data.frame': 3 obs. of 4 variables:
$ id : chr "A001" "A002" "A003"
$ name : chr "Mouse" "Keyboard" "USB"
$ price : num 30000 90000 50000
$ stringAsFactors: logi FALSE FALSE FALSE
mat <- matrix( c(1, 3, 5, 7, 9, 2, 4, 6, 8, 10, 2, 3, 5, 7, 11), ncol=3)
mat
[,1] [,2] [,3]
[1,] 1 2 2
[2,] 3 4 3
[3,] 5 6 5
[4,] 7 8 7
[5,] 9 10 11
as.data.frame(mat)
V1 V2 V3
1 1 2 2
2 3 4 3
3 5 6 5
4 7 8 7
5 9 10 11
number <- as.data.frame(mat)
number
V1 V2 V3
1 1 2 2
2 3 4 3
3 5 6 5
4 7 8 7
5 9 10 11
colnames(number) <- c("odd", "even", "prime")
number
odd even prime
1 1 2 2
2 3 4 3
3 5 6 5
4 7 8 7
5 9 10 11
v1 <- c("A001", "A002", "A003")
v2 <- c("Mouse", "Keyboard", "USB")
v3 <- c(30000, 90000, 50000)
lst <- list(v1, v2, v3)
lst
[[1]]
[1] "A001" "A002" "A003"
[[2]]
[1] "Mouse" "Keyboard" "USB"
[[3]]
[1] 30000 90000 50000
product <- as.data.frame(lst)
product
1 A001
2 A002
3 A003
c..Mouse....Keyboard....USB..
1 Mouse
2 Keyboard
3 USB
c.30000..90000..50000.
1 30000
2 90000
3 50000
colnames(product)
[1] "c..A001....A002....A003.."
[2] "c..Mouse....Keyboard....USB.."
[3] "c.30000..90000..50000."
colnames(product) <- c("id", "name", "price")
product
id name price
1 A001 Mouse 30000
2 A002 Keyboard 90000
3 A003 USB 50000
nrow(product)
[1] 3
ncol(product)
[1] 3
length(product)
[1] 3
'공부 > R Programming' 카테고리의 다른 글
R기초; 데이터프레임 인덱싱 - 1 (0) | 2021.01.09 |
---|---|
R 기초; 데이터프레임 확장 (0) | 2021.01.09 |
R 기초; 리스트 인덱싱-2 (0) | 2021.01.06 |
R 기초; 리스트 인덱싱-1 (0) | 2021.01.05 |
R기초; 리스트 생성 (0) | 2021.01.04 |
댓글