EpiMan
EpiMan

Reputation: 839

Error in 1:x : argument of length 0

I'm trying to read few files (like A, B, ...) in R, then for each file, iterate line by line, filter some rows using a certain cutoff, and save it in data.frame and later on make a plot. Instead of doing one by one, I tried to use nested loop and list, but it returns this error:

Error in 1:x : argument of length 0

my code:

A <- read.delim("A.txt",header=F)
B <- read.delim("B.txt",header=F)
C <- read.delim("C.txt",header=F)
D <- read.delim("D.txt",header=F)


mylist <- list (
  "A"=A,
  "B"=B,
  "C"=C,
  "D"=D
  )

#also tried mylist <- c("A","B","C","D")   




for (j in names(mylist)){
    x <- nrow(j) 
    d <- data.frame()
    for (i in 1:x){
      if(j[i,1]<0){
        d <- rbind(d, (j[i,]))
      }
      else {next}
    }

    #make plot

    }

Upvotes: 0

Views: 2529

Answers (1)

Hong Ooi
Hong Ooi

Reputation: 57686

for (j in names(mylist)){

This iterates over the names of your mylist object, so j will contain the strings "A", "B", "C" and so on. Calling nrow on this won't do anything sensible. You probably want to iterate over the contents of mylist:

for (j in mylist) {

Upvotes: 2

Related Questions