为什么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"
答案 0 :(得分: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"
答案 1 :(得分:1)
rbind
的第一个参数是...
,帮助文件是:
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’.)
并且字符转换可能是由于您的某个列表包含字符。