Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 206473

In a list of data frames, calculate proportion of these that meets a condition

$
0
0

I have a list of data frames (gtf) and I would like to calculate what proportion of each of these data frames have 0's at a set of coordinates [i,j] (coordinates [i,j] == 0). i.e. if I have 500 data frames and 120 of them have 0 at coordinates [1,1], then the function would return 120/500.

Eventually, I would like my function to return a data frame where the columns correspond to the columns of gtf and the values are the proportions of data frames that had 0's in the corresponding coordinates. Here is a recreation of gtf:

x = matrix(c(1,0), 6,6)
x = as.data.frame(x)
y = matrix(c(0,1), 6,6)
y = as.data.frame(x)
gtf = list(x,y,x,y)

Here is what I have tried:

for (i in seq_along(gtf)) 
    for (j in seq_along(gtf[[i]])) 
        if (gtf[[i]][1,j] == 0) tf[[i]] <- TRUE

Viewing all articles
Browse latest Browse all 206473

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>