Skip to content
Prev 8912 / 398502 Next

read data into R with some constraints

On Thu, 11 Jan 2001, Yu-Ling Wu wrote:

            
Um, read.csv uses sep =",", and you need header=FALSE.
You can't!  Until you have read the record, you cannot tell if all the
entries are positive.

Is this really a problem?  You only have around 120k numbers, and I just
did it very easily.

rawdata <- read.csv("data.csv", header=F)

Perhaps better is to use a matrix and scan():

rawdata <- matrix(scan("data.csv", sep=","), , 4, byrow=TRUE)
keep <- (rawdata <= 0) %*% rep(1,4) == 0
rawdata[keep, ]

Takes a few seconds and a few Mb.