0

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?

Chris Snow
  • 23,813
  • 35
  • 144
  • 309

2 Answers2

1

The first parameter expects the logical condition and second argument represent the columns.

The same functionality you are looking can be done by head(frame, no#OfRows)

airfile <- system.file("extdata", "airline.zip", package="bigr")
airfile <- unzip(airfile, exdir = tempdir())
airR <- read.csv(airfile, stringsAsFactors=F)
air <- as.bigr.frame(airR)
head(air, 4)

Refer: https://www.ibm.com/support/knowledgecenter/SSPT3X_4.0.0/com.ibm.swg.im.infosphere.biginsights.tut.doc/doc/tut_Less_BigR_Stat2.html

  • Thanks Nisanth, head will work for some use cases, but not all. Would you be able to provide an example of the first approach, e.g selecting rows 3:4 of the airfile dataset? – Chris Snow May 05 '16 at 07:32
1

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