Export a list into a CSV or TXT file in R

后端 未结 8 1971
遥遥无期
遥遥无期 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:32

    You can write your For loop to individually store dataframes from a list:

    allocation = list()
    
    for(i in 1:length(allocation)){
        write.csv(data.frame(allocation[[i]]), file = paste0(path, names(allocation)[i], '.csv'))
    }
    
    0 讨论(0)
  • 2020-11-27 16:34

    So essentially you have a list of lists, with mylist being the name of the main list and the first element being $f10010_1 which is printed out (and which contains 4 more lists).

    I think the easiest way to do this is to use lapply with the addition of dataframe (assuming that each list inside each element of the main list (like the lists in $f10010_1) has the same length):

    lapply(mylist, function(x) write.table( data.frame(x), 'test.csv'  , append= T, sep=',' ))
    

    The above will convert $f10010_1 into a dataframe then do the same with every other element and append one below the other in 'test.csv'

    You can also type ?write.table on your console to check what other arguments you need to pass when you write the table to a csv file e.g. whether you need row names or column names etc.

    0 讨论(0)
提交回复
热议问题