# Roger Palay copyright 2016-01-31 # Saline, MI 48176 # stem_leaf<-function( lcl_list, place=0) { # convert the list to the form dddsl where the l is # the leaf and the s becomes the stem chop_list <- floor(round( lcl_list, -place)/(10^place)) # we can sort this chop_list <- sort( chop_list ) # then produce the stems and the leaves leaf_list <- chop_list %% 10 stem_list <-floor( chop_list/10) n <- length(stem_list) branch <- paste(stem_list[1]," | ",leaf_list[1],sep="") old_stem <- stem_list[1] for (i in 2:n) { if( stem_list[i] == old_stem) { branch <- paste( branch, leaf_list[i], sep=" ")} else { cat( branch, "\n") branch <- paste(stem_list[i]," | ",leaf_list[i],sep="") old_stem <- stem_list[i]} } cat( branch, "\n" ) }