MFR MFR - 1 year ago 58
R Question

issue in appending rows in a dataframe

I have the following code that everthing is alright, even the file generated in "C:/Users/User/Desktop/test/4.csv" is correct

d <- data.frame()
for(i in 1:nrow(testresult))
b<- pnbd.ConditionalExpectedTransactions(est.params, = testresult [i,8],
x, t.x,

m6<- list(testresult[i,1],b)

d <- rbind(d,m6)

write.table(m6,file="C:/Users/User/Desktop/test/4.csv", append=TRUE,sep=",",col.names=FALSE,row.names=FALSE)

I need a data frame similar to "C:/Users/User/Desktop/test/4.csv". That's why I added

d <- rbind(d,m6)

to append the new rows to my dataframe. The results for
is some repeated rows. Hope I am clear. Please ignore line 4 of the code if they are not clear. They are not the issue. the issue is only d <- rbind(d,m6)

Answer Source

Posting as an answer:

Your object m6 is a list and so cannot be attached to a dataframe using rbind. It depends on the output from your function pnbd.ConditionalExpectedTransactions but what you probably want is to create a vector using m6 <- c(testresult[i,1], b).