You're close, but you won't be off the hook that easy. I haven't checked the code, but I'm guessing that write.table
coerces your list to a data.frame before pushing the contents to a file, as demonstrated here:
> as.data.frame(a_list)
x y z
1 2 sdsd 2323322
This is fine, but you want it in reverse, where columns should be row names. You can use function t()
for that.
> t(as.data.frame(a_list))
[,1]
x "2"
y "sdsd"
z "2323322"
This is now ready to be pushed to a write.table
, which can be customized to do your bidding.
Here I explicitly turned row names on (it's already the default) and turned column names off. Quotes are not needed in this case so they're off as well.
write.table(t(as.data.frame(a_list)),
file = "myfile.txt",
row.names = TRUE,
col.names = FALSE,
quote = FALSE)
Contents of myfile.txt
:
x 2
y sdsd
z 2323322
If you are hell-bent on having commas after letters, you can do
out <- t(as.data.frame(a_list))
rownames(out) <- paste(rownames(out), ",", sep = "")
write.table(out,
file = "myfile.txt",
row.names = TRUE,
col.names = FALSE,
quote = FALSE)
x, 2
y, sdsd
z, 2323322