Note that there are some explanatory texts on larger screens.

plurals
  1. POprinting a list of dataframes
    primarykey
    data
    text
    <p>I am a relative newcomer to R. I have searched for the last two workdays trying to figure this out and failed. I have a list of factors generated by a function. I have 9 items in the list of different lengths.</p> <pre><code>&gt;summary(list_dataframes) Length Class Mode [1,] 1757 factor numeric [2,] 1776 factor numeric [3,] 1737 factor numeric [4,] 1766 factor numeric [5,] 1783 factor numeric [6,] 1751 factor numeric [7,] 1744 factor numeric [8,] 1749 factor numeric [9,] 1757 factor numeric </code></pre> <p>Part of a sample of the data as it comes out:</p> <blockquote> <p>list_dataframes</p> </blockquote> <pre><code>[[1]] [1] 1776234_at 1779003_at 1776344_at 1777664_at 1772541_at 1774525_at [[2]] [1] 1771703_at 1776299_at 1772744_at 1780116_at 1775451_at 1778821_at [7] 1774342_at [[3]] [1] 1780116_at 1776262_at 1775451_at 1780200_at 1775704_at </code></pre> <p>I am not sure why it says the Mode is "numeric". The individual entries are a mix of numbers and letter like "S35_at".</p> <p>I would like to make this into a table of nine columns and 1783 rows without making duplicate values. (Hence I tried using do.call and it didn't work. I ended up with a mess full of duplicates.) The shorter ones can have NAs in the empty spaces or be blank. </p> <p>I need to be able to eventually end up with something I can put into a spread sheet.</p> <p>There has to be a way to do this. Thank you!</p> <p>I guess I should add it initially was coming out as data frames when I had four columns of data but I only need one column of the data and when I subsetted the function that creates this list to create only the one column I actually needed it seems to no longer be a dataframe.</p> <pre><code>dput(head(list_dataframes)) list(structure(c(3605L, 5065L, 3663L, 4349L, 1655L, 2700L, 5692L, plus many more .Label = c("1769308_at", "1769311_at", "1769312_at", "1769313_at", "1769314_at", "1769317_at", plus many more this pattern is repeated nine more times </code></pre> <p>What I am trying to do is produce a table that would look like this:</p> <pre><code>a= xyz,tuv,efg,hij,def b= xyz,tuv,efg c= tuv,efg,hij,def </code></pre> <p>What I want to make is a table that is</p> <pre><code>a b c xyz xyz tuv tuv tuv efg efg efg hij hij NA NA NA NA NA NA could be blank as well. </code></pre> <p>After much reading the manual section on lists I determined that I had generated a buried list of lists. It had nine items with the data I wanted buried two layers down i.e to see it I had to use [[1]]. Also because of something in R that results in a single column data frame becoming a factor instead of staying a data frame it was further complicated. To fix it (sort of) I added one step in my equation so that I changed that factor into a data frame.</p> <p>After that, when I used lapply to generate my result, at least the factor issue was resolved. I could then use the following steps to pull the data frames out.</p> <pre><code>first &lt;- list_dataframes[[1]] second &lt;- list_dataframes[[2]] third &lt;- list_dataframes[[3]] fourth &lt;- list_dataframes[[4]] fifth &lt;- list_dataframes[[5]] sixth &lt;- list_dataframes[[6]] seventh &lt;- list_dataframes[[7]] eighth &lt;- list_dataframes[[8]] nineth &lt;- list_dataframes[[9]] all_results &lt;- cbindX(first,second,third,fourth,fifth,sixth,seventh, eighth,nineth) </code></pre> <p>I could then write the csv file using write.csv and get the correct result I was after. SO I guess I have my answer. I mean it does work now.</p> <p>However I still think I am missing something in making this work optimally even though it is now giving me the correct result I was after.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload