Reputation: 4229
I have list of dataframes like this:
listdata <- list(matrix(c(1,1,1,1,3,3,3,3),nrow=2,ncol=4),matrix(c(1,1,1,1,2,2,2,2),ncol=1),matrix(c(1,1,1,1,2,2,2,2),nrow=2))
FrameData <- lapply(listdata, function(x) as.data.frame(x))
How I would rbind the list od dataframes so that I would exclude the 1 column vector? The final output I would like is:
V1 V2 V3 V4
1 1 1 3 3
2 1 1 3 3
3 1 1 2 2
4 1 1 2 2
Upvotes: 1
Views: 115
Reputation: 206382
You can do this by subsetting your list and using a do.call
do.call(rbind, FrameData[sapply(FrameData, function(x) ncol(x)>1)])
# V1 V2 V3 V4
# 1 1 1 3 3
# 2 1 1 3 3
# 3 1 1 2 2
# 4 1 1 2 2
Here i just check that each data.frame has more than one column
Upvotes: 2