Reputation: 185
Consider the iris dataset in R. (available in Julia via RDatasets package). Suppose I want to get the observations of "Sepal.Length" and "Petal.Width" for Species "setosa". In R, I can do it by:
subset(iris, Species=="setosa", select = c(Sepal.Length, Petal.Width))
Is there any similar function in Julia for the same job?
Upvotes: 3
Views: 393
Reputation: 5756
using RDatasets
iris = dataset("datasets","iris") # typeof(iris) => DataFrames.DataFrame
subset=iris[iris[:Species].=="setosa",[:PetalLength,:PetalWidth]]
Notes(1) refer to RDatasets.jl:
In order to load one of the data sets included in the
RDatasets
package, you will need to have theDataFrames
package installed. This package is automatically installed as a dependency of theRDatasets
package if you installRDatasets
as follows:
Pkg.add("RDatasets")
Note(2): as datasets
in RDatasets
package are of DataFrame
type, so one can use syntax from dataframesjl to create Subsets
EDIT:
As @jverzani commented, using DataFramesMeta
unveils a set of macros with SQL
semantics that guides users to write query statements in more familiar styles. e.g the above command would be @ix(iris, :Species.=="setosa", [:PetalLength,:PetalWidth])
Upvotes: 2