Skip to content

Error

2 messages · Nikita Dinger, Bert Gunter

#
Dear Sir,

I am getting this error

Error in rep(xi, length.out = nvar) :
  attempt to replicate an object of type 'closure'

I have read through the websites but cant really comprehend what this means?
Need your help.

This is my code

complete <- function(directory, idvec = 1:332) {
        df <- data.frame(id = integer(), nobs = integer())
    for (id in idvec) {
        filename <- paste(directory, "/",
                          sprintf("%03d", as.integer(id)),
                          ".csv", sep = "")
filename <- list.files()
        data <- rbind(data, read.csv(filename[id]))
}
str(data)
for (id in idvec)
        {nd <- data.frame(id = id,
                         nobs = nrow(na.omit(data)))
        df <- rbind(df, nd)
    }
    return(df)

}
#
What do you think "data" is in:

rbind(data, read.csv(filename[id]))

str(data) ## before running your function

will show you that it is probably the built in function data() which
is probably the source of your error.


Cheers,
Bert


Bert Gunter

"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
   -- Clifford Stoll
On Sun, Aug 16, 2015 at 2:01 AM, Nikita Dinger <dingernikita at gmail.com> wrote: