r - Created a dataframe within a function and used rbind to add rows, but its first row is NA's, by default not choise -


i @ beginning level. think question regarding rbind , initializing data frame named com, use below.

-- u can skip this-- function takes in 2 parameters, directory , id, directory open appropriate folder in workspace, , id pulls out relevant csv file-- part --.

below function, , under output, in output see first row has na na. learn going on, how make such first row in not na's thanks.

complete <- function(directory, id = 1:332) {        com <- data.frame(matrix(ncol=2))       names(com) <- c("id","nobs")       #initialize com, data frame store entries into.        for(i in id) {         x <- paste("./", directory, "/",list.files(paste("./", directory, sep=""))[i], sep="")         q <- read.table(x,sep=",", header=t)         u <- complete.cases(q)          n_r <- (nrow(q[u,]))          entry <- c(i,n_r)          com<-rbind(com,entry)       }       return(com)     }   

this output, when tried same approach in different function 1st row not na's, in case difference 2 data frames combined rbind , both had same col names.

> complete("specdata", 30:25)       id nobs     1 na   na     2 30  932     3 29  711     4 28  475     5 27  338     6 26  586     7 25  463 

is there leaned here knowledge gained. again.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -