dataframe - R - extract row as character string with double quote -


i have data frame called dataf

dataf<-data.frame(replicate(10,sample(0:1,10,rep=true))) 

and extract each row of data frame character string function :

result=data.frame(matrix(na, ncol=1, nrow=10))  i=0 for(i in 0:9) {   result[i+1,]=tostring(dataf[i+1,]) } 

but result not expected :

1, 0, 0, 0, 1, 0, 0, 1, 1, 0 0, 0, 0, 1, 1, 1, 1, 0, 1, 1 1, 1, 0, 0, 0, 0, 0, 0, 1, 0 

i this:

"1","0","0","0","1","0","0","1","1","0" "0","0","0","1","1","1","1","0","1","1" "1","1","0","0","0","0","0","0","1","0" 

i tried dquote, \"r\", collapse, sep... don't need.

try: capture.output(write.table(lapply(dataf, as.character), row.names=f, col.names=f, sep=","))

 [1] "\"0\",\"0\",\"0\",\"0\",\"1\",\"1\",\"1\",\"1\",\"1\",\"1\""  [2] "\"1\",\"0\",\"1\",\"0\",\"0\",\"0\",\"1\",\"0\",\"1\",\"1\""  [3] "\"0\",\"1\",\"0\",\"0\",\"1\",\"1\",\"0\",\"0\",\"1\",\"1\"" ... 

edited in response matthew's comment below


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -