Say I have 900 dataframes at hand, and I wanted to get something similar to a frequency distribution based off of another column for each "type".
Sample Code makin;
df1 <- as_tibble(iris)
df2 <- slice(df1, 1:7)
df2 <- df2 %>%
mutate(type = 1:7)
This is similar to what I currently have just working with one dataframe:
df2 %>% select(type, Sepal.Length) %>%
mutate(Count = ifelse(Sepal.Length > 0, 1, 0)) %>%
mutate(Percentage = Count/7)
In the case that for any row, Sepal.Length = 0, then I'm not going to count it (count column will be = 0 for that row value).
But I'm going to have 900 dataframes that I'll be running this code on, so I was thinking about running it through a loop.
Ideally, if two dataframes are inputted, and both have Sepal.Length values >0 for row 1, then I want the count to be 2 for row 1 / type 1. Is there a better way to approach this? And if I do go for the looping option then is there a way to combine all the dataframes to tell R that row 1 / type 1 has multiple > 0 values?