In R, a user has a list like the following and he wants to print this list to a text file.How to do that?

465    Asked by Unnatigautam in Data Science , Asked on Dec 2, 2019
Answered by Unnati gautam

print(head(mylist,2))

[[1]]

[1] 2349 103 411 9321 4268

[[2]]

[1] 16937 162

For printing all the elements of a list given to a text file, we can perform lapply() function to pass into a list and append into a text file as an output such as

lapply(mylist, write, "outputfile.txt",append=TRUE, ncolumns=1000)



Your Answer

Interviews

Parent Categories