2016-08-29 2 views
1

data.frameへの最後のキャストが機能しないように見えるのはなぜですか?私はそれを並べ替えるしようとすると私が取得:OPのデータセットのError in order(temp[, 1], decreasing = T) : unimplemented type 'list' in 'orderVector1'列をソートするためにdata.frameにキャストできません。実装されていない型リスト

data<-lapply(1:5,function(i){ 
    lapply(1:5,function(j){ 
    list(i=i,j=j) 
    }) 
}) 

temp<-as.data.frame(data) 
temp<-matrix(temp,ncol=2,byrow=T) 
head(temp,20) 
temp<-data.frame(temp) 
class(temp) #####IS A DATA.FRAME 
temp<-temp[order(temp[,1],decreasing=T),] 
+1

からCJを使用して。これを解決策として投稿してください。 – Rilcon42

答えて

0

列は、私たちが列vector sの通常のdata.frameに変換することができlength 25の各listです。

temp1 <- data.frame(lapply(temp, unlist)) 

、その後はorder

temp1[order(temp1[,1], decreasing = TRUE),] 

またstr

str(temp, list.len = 3) 
#'data.frame': 25 obs. of 2 variables: 
# $ X1:List of 25 
# ..$ : int 1 
# ..$ : int 1 
# ..$ : int 1 
# .. [list output truncated] 
# $ X2:List of 25 
# ..$ : int 1 
# ..$ : int 2 
# ..$ : int 3 
# .. [list output truncated] 

とデータセットの構造を確認することが容易である、我々は直接取得することができません

expand.grid(rep(list(1:5), 2)) 

または私は必要なものだったdata.table

library(data.table) 
CJ(1:5, 1:5) 
関連する問題