Q:

Count rows of a data frame which do not contain `NA`

Possible Duplicate:
R - remove rows with NAs in data.frame 

I have a data frame derived from the following function:
complete <- function(directory,id = 1:332) {

   csvfiles <- sprintf("/Users/myname/Desktop/%s/%03d.csv", directory, id)

   nrows <- sapply( csvfiles, function(f) nrow(read.csv(f)))

        rowlabels <- nrow(nrows)

        data.frame(id=sprintf('%3d', id), 
            nobs=sapply(csvfiles,function(x) length(count.fields(x))),
            row.names=rowlabels
           )
       }

This function counts the number of rows in each file contained within the directory produced by the object csvfiles. It then outputs a data frame showing the file number along with the count of rows (so two columns)
Thought I had it but problem is that I must now exclude rows within each file where an instance of NA exists.
How would I edit this to ignore those rows in each file and just count the rows where no NAs exist?

A:

Replace this line:

nrows <- sapply( csvfiles, function(f) nrow(read.csv(f)))

with this line, which uses the complete.cases function:

nrows <- sapply( csvfiles, function(f) nrow(complete.cases(read.csv(f))))

complete.cases takes a data frame and returns a data frame with the same columns, but with all the rows which contain at least one NA thrown out.

