[R] Populating then sorting a matrix and/or data.frame

Noah Silverman noah at smartmediacorp.com
Thu Nov 11 06:02:22 CET 2010


I have a process in R that produces a lot of output.  My plan was to 
build up a matrix or data.frame "row by row", so that I'll have a nice 
object with all the resulting data.

I started with:
results <- matrix(ncol=3)
names(results) <- c("one", "two", "three")

Then, when looping through the data:
results <- rbind(results, c(a,b,c))

This seems to work fine. BUT, my problem arises when I want to filter, 
sort, etc.

I tried (thinking like a data.frame):
results[results$c < 100,]

But that fails.

I tried making it a data.frame with
foo <- data.frame(results)

But that converted all the numeric values to factors!!!  Which causes a 
whole mess of problems.

Any ideas??


More information about the R-help mailing list