R split()

1 개요[ | ]

R split()
  • "Divide Into Groups And Reassemble"
mydf = iris[seq(1, nrow(iris), 20),]
mydf
##     Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
## 1            5.1         3.5          1.4         0.2     setosa
## 21           5.4         3.4          1.7         0.2     setosa
## 41           5.0         3.5          1.3         0.3     setosa
## 61           5.0         2.0          3.5         1.0 versicolor
## 81           5.5         2.4          3.8         1.1 versicolor
## 101          6.3         3.3          6.0         2.5  virginica
## 121          6.9         3.2          5.7         2.3  virginica
## 141          6.7         3.1          5.6         2.4  virginica

split(mydf, mydf$Species)
## $setosa
##    Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1           5.1         3.5          1.4         0.2  setosa
## 21          5.4         3.4          1.7         0.2  setosa
## 41          5.0         3.5          1.3         0.3  setosa
## 
## $versicolor
##    Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
## 61          5.0         2.0          3.5         1.0 versicolor
## 81          5.5         2.4          3.8         1.1 versicolor
## 
## $virginica
##     Sepal.Length Sepal.Width Petal.Length Petal.Width   Species
## 101          6.3         3.3          6.0         2.5 virginica
## 121          6.9         3.2          5.7         2.3 virginica
## 141          6.7         3.1          5.6         2.4 virginica

2 같이 보기[ | ]

3 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}