I have a function that will return a numeric class object, here is a simplified version:
count.matches <- function(x) {
ifelse(!is.na(a[,x] & a[,2]),1,0)
}
it just produces an object of 0s and 1s. For example
count.matches(4)
[1] 0 0 0 0 1 1 0
I just want to do a simple for loop of this function and store the results in a data frame, i.e. each time the function loops through create a column, however I am having trouble.
p <- data.frame()
my.matches <- for(i in 2:100) {
p[i,] <- count.matches(i)
}
This produces nothing. Sorry if this is a really stupid question, but I have tried a bunch of things and nothing seems to work. If you need any more information, please let me know and I will provide it.