Export a list into a CSV or TXT file in R

后端 未结 8 2024
遥遥无期
遥遥无期 2020-11-27 16:02

I\'m sorry to ask this question. I\'m very noob with R. I know there is a lot of threads which are related to the very same problem. I understood that we cannot export a tab

8条回答
  •  心在旅途
    2020-11-27 16:14

    You can simply wrap your list as a data.frame (data.frame is in fact a special kind of list). Here is an example:

    mylist = list() 
    mylist[["a"]] = 1:10 
    mylist[["b"]] = letters[1:10]
    write.table(as.data.frame(mylist),file="mylist.csv", quote=F,sep=",",row.names=F)
    

    or alternatively you can use write.csv (a wrapper around write.table). For the conversion of the list , you can use both as.data.frame(mylist) and data.frame(mylist).

    To help in making a reproducible example, you can use functions like dput on your data.

提交回复
热议问题