user2543622
user2543622

Reputation: 6796

r write list to table

I have a list as below:

l1=list()
l1[[1]]="YES"
l1[[2]]="NO"
l1
> l1
[[1]]
[1] "YES"

[[2]]
[1] "NO"

I want to write it to a table (something like write.table(answer, row.names = F, col.names = F)). Please note - output shouldn't have any "" and each element on a new line.

The table should have:

YES
NO

Upvotes: 0

Views: 831

Answers (2)

Ronak Shah
Ronak Shah

Reputation: 389235

How about using data.table?

install.packages("data.table")
library(data.table)

l1 <- data.table(l1)

> l1
l1
#1: YES
#2:  NO

Upvotes: 1

Rich Scriven
Rich Scriven

Reputation: 99371

Either of these should work for you

x <- list("YES", "NO")

write.table(do.call(rbind, x), quote = FALSE, row.names = FALSE, col.names = FALSE)
# YES
# NO
cat(unlist(x), sep = "\n")
# YES
# NO

There are file arguments in each of these functions for writing to file.

Upvotes: 4

Related Questions