SHARE
TWEET

Untitled

a guest Jun 26th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. mytable <- function(...) {
  2.     tab <- ftable(...)
  3.     prop <- prop.table(x = tab,
  4.                        margin = 2) * 100
  5.     bind <- cbind(as.matrix(x = tab),
  6.                   as.matrix(x = prop))
  7.     margin <- addmargins(A = bind,
  8.                          margin = 1)
  9.     round(x = margin,
  10.           digits = 1)}
  11.  
  12. # dummy example
  13. mytable(formula = wool + tension ~ breaks,
  14.         data = warpbreaks)
  15.  
  16.     A_L A_M A_H B_L B_M B_H   A_L   A_M   A_H   B_L   B_M   B_H
  17. 10    0   0   1   0   0   0   0.0   0.0  11.1   0.0   0.0   0.0
  18. 12    0   1   0   0   0   0   0.0  11.1   0.0   0.0   0.0   0.0
  19. 13    0   0   0   0   0   1   0.0   0.0   0.0   0.0   0.0  11.1
  20. 14    0   0   0   1   0   0   0.0   0.0   0.0  11.1   0.0   0.0
  21. 15    0   0   1   0   0   2   0.0   0.0  11.1   0.0   0.0  22.2
  22. ...
  23. Sum   9   9   9   9   9   9 100.0 100.0 100.0 100.0 100.0 100.0
  24.      
  25. # dummy example
  26. mytable(formula = wool + tension ~ breaks,
  27.         data = warpbreaks,
  28.         subset = breaks < 20)
  29.  
  30.  Error in eval(substitute(subset), data, env) :
  31.   ..3 used in an incorrect context, no ... to look in
  32.      
  33. mytable <- function(formula,
  34.                     data,
  35.                     subset) ftable(formula = formula,
  36.                                    data = data,
  37.                                    subset = subset)
  38.  
  39. mytable(formula = wool + tension ~ breaks,
  40.         data = warpbreaks,
  41.         subset = breaks < 20)
  42.  
  43.  Error in xj[i] : invalid subscript type 'closure'
  44.      
  45. mytable <- function(...) {
  46.   do.call(what = ftable,
  47.           args = as.list(x = match.call()[-1]))
  48.   #etc
  49. }
  50.      
  51. mytable <- function(...) {
  52.   mc <- match.call()
  53.   mc[[1]] <- quote(expr = ftable)
  54.   eval(expr = mc)
  55.   # etc
  56. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top