I have a simple question but it cost me hours. I would like to cbind() a matrix and a dataframe. The point is, they don't have equal lengths.
matrix:
condition
[,1]
ILMN_1666845 TRUE
ILMN_1716400 TRUE
Data.frame
a
t1 t2 t3 t4 1 0 1 1 1
If I use cbind() without a loop, everything is ok and this is the result:
b<-cbind(condition,a) b
condition t1 t2 t3 t4
ILMN_1666845 TRUE 0 1 1 1
ILMN_1716400 TRUE 0 1 1 1
But in a for loop I get the following error: Error in data.frame(..., check.names = FALSE) : arguments imply differing number of rows: 0, 1
Can anyone help me? Thanks!
For loop code:
for (p in 1:nrow(outcomes)) {
id <- apply(regulationtable, 1, function(i)
sum(i[1:length(regulationtable)] != outcomes[p,])==0)
idd<-as.matrix(id)
condition = subset(idd, idd[,1]==TRUE)
a<-as.data.frame(t(outcomes[p,]))
b<-cbind(condition,a)
write.table(b, "file.txt", append=TRUE)}