[R] by function does not separate output from function with, mulliple parts

Leonard Mada |eo@m@d@ @end|ng |rom @yon|c@eu
Wed Oct 25 14:43:09 CEST 2023


Dear John,

Printing inside the function is problematic. Your function itself does 
NOT print the labels.

Just as a clarification:

F = factor(rep(1:2, 2))
by(data.frame(V = 1:4, F = F), F, function(x) { print(x); return(NULL); } )
#   V F
# 1 1 1
# 3 3 1
#   V F
# 2 2 2
# 4 4 2
# F: 1 <- this is NOT printed inside the function
# NULL
# ---------------------------------------------------------
# F: 2
# NULL

### Return Results
by(data.frame(V = 1:4, F = F), F, function(x) { return(x); } )
# F: 1
#   V F
# 1 1 1
# 3 3 1
# --------------------------------------------------
# F: 2
#   V F
# 2 2 2
# 4 4 2

Maybe others on the list can offer further assistance.

Sincerely,

Leonard



More information about the R-help mailing list