Search code examples
rbiginsightsbigr

how to select by index from a bigr.frame?


In standard r, I can select by index using something like the following:

newdf <- df[1:4,]

However, if I try the above on a bigr.frame, I get:

Error: BigR[bigr.frame.[]]: The given filtering condition must be a logical bigr.vector.

The documentation for [ {bigr} is as follows:

Description

Filter rows and project columns of a dataset

Usage

"["(x, i, j, ..., drop = TRUE)

Arguments

x (bigr.frame or bigr.matrix) the object being operated on. If x is a bigr.frame or bigr.csv.matrix, both filtering and projection are supported. If x is a bigr.binary.matrix, only projections are supported.

i (bigr.vector) a logical operation that represents the filtering condition (only for bigr.frame and bigr.matrix objects)

j (character or integer) a vector representing columns to be projected. These could be column ids (i.e., integers) or column names (i.e., characters)

drop in the case of projecting one single column, parameter drop determines whether the result should be a bigr.vector (drop=TRUE) or a bigr.frame (drop=FALSE). Default value is drop=TRUE.

Value

the derived bigr.frame, bigr.matrix, or bigr.vector

See Also

bigr.frame bigr.matrix

Examples

air[air$UniqueCarrier %in% c("UA", "HA"), c(1,2,3,5:9)]

air[, c("Origin", "Dest")]

air[air$Dest == "SFO", 17]

class(air[, 17, drop=FALSE])

class(air[, 17, drop=TRUE])

It isn't clear to me if I can select by index. Is this possible? How?


Solution

  • You can use as.data.frame function.

    Refer: https://www.ibm.com/support/knowledgecenter/SSPT3X_4.0.0/com.ibm.swg.im.infosphere.biginsights.bigr.doc/doc/frame_as.data.frame.html?lang=en

    airfile <- system.file("extdata", "airline.zip", package="bigr")

    airfile <- unzip(airfile, exdir = tempdir())

    airR <- read.csv(airfile, stringsAsFactors=F)

    air <- as.bigr.frame(airR)

    airdf <- as.data.frame(air)

    newdf <- airdf[1:4,]

    newdf