Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom R function returning weird output
    primarykey
    data
    text
    <p>So I'm trying to create a list of lists of data frames, basically for the purposes of passing them to multiple cores via mclapply. But that's not the part I'm having trouble with. I wrote a function to create a list of smaller data frames from one large data frame, and then applied it sequentially to break a large data frame down into a list of lists of small data frames. The problem is that when the function is called the second time (via lapply to the first list of data frames), it's adding extra small data frames to each list of data frames in the larger list. I have no idea why. I don't think it's the lapply, since when I ran the function manually on one frame from the first list it also did work. Here's the code:</p> <pre><code>create_frame_list&lt;-function(mydata,mystep,elnames){ datalim&lt;-dim(mydata)[1] mylist&lt;-list() init&lt;-1 top&lt;-mystep i&lt;-1 repeat{ if(top &lt; datalim){ mylist[[i]]&lt;-assign(paste(elnames,as.character(i),sep=""),data.frame(mydata[init:top,])) } else { mylist[[i]]&lt;-assign(paste(elnames,as.character(i),sep=""),data.frame(mydata[init:datalim,])) } if(top &gt; datalim){break} i&lt;-i+1 init&lt;-top+1 top&lt;-top+mystep } return(mylist) } test_data&lt;-data.frame(replicate(10,sample(0:1,1000,rep=TRUE))) #Create the first list of data frames, works fine master_list&lt;-create_frame_list(test_data,300,"bd") #check the dimensions of the data frames created, they are correct lapply(master_list,dim) #create a list of lists of data frames, doesn't work right list_list&lt;-lapply(master_list,create_frame_list,50,"children") #check the dimensions of the data frames in the various lists. The function when called again is making extra data frames of length 2 for no reason I can see lapply(list_list,lapply,dim) </code></pre> <p>So that's it. Any help is appreciated as always.</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