I am trying to get the position of the first occurrence of a value 0 in a number of binary matrices read in through a number of csv files.
I have got the the number of 0s using...
sapply(files_to_use, function(x) sum(x == 0))
After reading in all csv files using...
reading_in_csv <- list.files(pattern="*.csv")
files_to_use <- lapply(reading_in_csv, read.delim)
I have tried the following code but get the error 'dim(X) must have a positive length'...
find_first_0 <- function(x){which(x = 0)}
apply(files,1,find_first_0)
Would anyone have any insight on the above. I was thinking of the function which() to get the position but I have no understanding with how to implement it with a number of matrices at once.
Given example matrix...
dimMat <- matrix(0, 1000, 10)
for(i in 1:1000){
dimMat[i, ] <- sample(c(0,1), 10, replace = TRUE, prob = c(.3, .7))
}
print(dimMat)
It is ugly but i think this is what you are after: