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 <dingernik...@gmail.com> wrote: > 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) > > } > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.