how to store the printed output from a function as a vector in R?

I have the following column from a dataframe df <- data.frame( crime = as.character(c(115400, 171200, 91124, 263899, 67601, 51322)), stringsAsFactors=FALSE ) I am using a function to extract the first two digits based on some condition as seen on the function below for (i in df$crime){ if (nchar(i)==6){ print(substring(i,1,2))} else {print(substring(i,1,1)) } } when I…

Details