Debuggin函数翻译

问题描述 投票:0回答:1

我试图将matrix函数参数“翻译”成葡萄牙语,是这样做的:

portuguese.matrix <- function(dados = NA, nlin = 1, ncol = 1, porlin = FALSE,
                              dimnomes = NULL) {
    matrix(data, nrow, ncol, byrow,
           dimnames)
}

所以,我试图获得此输出:

matrix(data = rnorm(9) ,nrow = 3, ncol = 3, dimnames = list(c("a","b","c"),c("d","e","f")))

            d          e         f
a  0.01874617 -0.5991677 -1.208076
b -0.18425254  0.2945451 -0.363676
c -1.37133055  0.3897943 -1.626673

这就是我得到的:

portuguese.matrix(dados = rnorm(9) ,nlin = 3, ncol = 3, dimnomes = list(c("a","b","c"),c("d","e","f")))
Error in as.vector(x, mode) : 
  cannot coerce type 'closure' to vector of type 'any'
Called from: as.vector(data)
Browse[1]> 

R studio打开一个显示此窗口:

enter image description here

有关解决此问题的任何技巧?

r function
1个回答
0
投票

您是否正在寻找类似的东西?

portuguese.matrix <- function(dados = NA, nlin = 1, ncol = 1, porlin = FALSE, dimnomes = NULL) {
  matrix(data = dados,
         nrow = nlin,
         ncol = ncol,
         byrow = porlin,
         dimnames = dimnomes)
 }

 set.seed(123) 
 portuguese.matrix(dados = rnorm(9) ,nlin = 3, ncol = 3, dimnomes =  list(c("a","b","c"),c("d","e","f")))

当使用随机数功能固定输出时,可以使用set.seed(number)

我得到了这个输出:

structure(c(-0.560475646552213, -0.23017748948328, 1.55870831414912, 
0.070508391424576, 0.129287735160946, 1.71506498688328, 0.460916205989202, 
-1.26506123460653, -0.686852851893526), .Dim = c(3L, 3L), .Dimnames = list(
    c("a", "b", "c"), c("d", "e", "f")))
© www.soinside.com 2019 - 2024. All rights reserved.