myFunction <- function(x){ for(i in 0:23) { if(i<10){ timer <- paste("T0",i, sep ="") tempr <- grepl(timer,x) tempr <- table(tempr)["TRUE"] timeCount <- c(timer,tempr) } else{ timer <- paste("T",i,sep="") tempr <- grepl(timer,x) tempr <- table(tempr)["TRUE"] timeCount <- c(timer,tempr) } } return(timeCount) } tmp <- myFunction(test$timestamp) What I am trying to do is in the function I am looping for 23 times and generating two values timer (contains values like T00, T01, T02...T23) and tempr (contains values like 23, 24, 25...). Now I want to store all the 23 respective values for the two variables in a dataframe so that my final output is
TimeZ Freq T00 33 T01 12 T02 22 T04 34 . . . . . . T23 23