2012-03-01 3 views
3

なぜrbindは数字要素のリストを文字に変換しますか?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

最小限の再現可能な例を投稿すると、助けが簡単になります。 – Andrie

+1

あなたは 'lapply(mymatrix.list、class)'を提供しているはずです。 –

答えて

4

おそらくリストの項目の1つに文字が含まれているためですか?

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" 
+0

実際、私のプログラムのバグです。私は文字の種類のリストの要素の1つを持っていました。 –

1

rbindの最初のarguementは...で、ヘルプファイルは読み取ります

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’.) 

と文字変換が原因の文字を含むあなたのリストのいずれかにありそうです。

関連する問題