Hi I am new to learning R.
I am running a loop to find out number of man based on their region and value "v" in data frame specified bellow. I would like to save the result of the loop to data frame so that I can work with it. Thank you for your help.
data<-data.frame(x=rep(c("man", "woman"),500),reg=rep(1:5, 200), v=c(seq(100,1,length.out = 500),c(seq(1,100,length.out = 500))))
for (i in seq(0, 100, 10)) {
print(paste("interval <", i, "-", i+10,">"))
data %>%
filter(data$x == "man" & data$v >= i & data$v <= i +10) %>%
group_by(Region = reg) %>%
summarize(No_man = n()) %>%
as.data.frame() %>%
print()
if (i+10 > 90) {break}
}
tempdat <- data %>% .... I think this would be the easiest way out of your predicament.