4

为什么 rbind 将我的数字元素列表转换为字符?

> class(mymatrix.list)
[1] "list"
> class(mymatrix.list[[1]])
[1] "numeric"
> mymatrix.results = do.call(rbind, mymatrix.list)
> class(mymatrix.results)
[1] "matrix"
> class(mymatrix.results[1])
[1] "character"
4

2 回答 2

4

可能是因为您列表中的一项包含字符?

mymatrix.list <- list()
for(i in 1:10){
  mymatrix.list[[i]] <- rnorm(26)
}

class(mymatrix.list)
# [1] "list"
class(mymatrix.list[[1]])
# [1] "numeric"
mymatrix <- do.call(rbind, mymatrix.list)
class(mymatrix)
# [1] "matrix"
class(mymatrix[1])
# [1] "numeric"

## Add a character vector to your list
mymatrix.list[[11]] <- LETTERS
mymatrix <- do.call(rbind, mymatrix.list)
class(mymatrix)
# [1] "matrix"
class(mymatrix[1])
# [1] "character"
于 2012-03-01T15:32:32.553 回答
2

rbindis的第一个论点...和帮助文件如下:

Arguments:

     ...: vectors or matrices.  These can be given as named arguments.
          Other R objects will be coerced as appropriate: see sections
          ‘Details’ and ‘Value’.  (For the ‘"data.frame"’ method of
          ‘cbind’ these can be further arguments to ‘data.frame’ such
          as ‘stringsAsFactors’.)

并且字符转换可能是由于您的列表之一包含字符。

于 2012-03-01T15:33:33.847 回答