warning :: Coercing LHS to a list

Published by onesixx on

 

df<-iris
dtrace <- apply(df, 1,function(x){
    tt<-x[3]
    tt$wid <- x[1]
    return(tt)
})
#dtrace <- ldply(dtrace, rbind)[,-1]
result<-rbindlist(dtrace, use.names=TRUE, fill=TRUE)
result

 

df<-iris
dtrace <- apply(df, 1,function(x){
    tt<-c(x[3],wid=x[4])
    return(tt)
})
result<-t(dtrace)

 

left hand side

In  tt$wid <- x[1] : Coercing LHS to a list

$연산자를 matrix의 subset하기위해 사용하면 안된다. ( 새로운 컬럼을 추가할때 쓴다)

 

dtrace <- apply(df, 1,function(x){
    tt<-x[3]
    tt$wid <- x[1]
    return(tt)
})

 

> class(dtrace)
[1] "list"
> dim(dtrace)
NULL

 

> head(dtrace)
[[1]]
[[1]]$Petal.Length
[1] 1.4

[[1]]$wid
Sepal.Length 
         5.1 


[[2]]
[[2]]$Petal.Length
[1] 1.4

[[2]]$wid
Sepal.Length 
         4.9 


[[3]]
[[3]]$Petal.Length
[1] 1.3

[[3]]$wid
Sepal.Length 
         4.7 

 

 

 

Categories: Uncategorized

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x