[R] row combining 2972 files

Dénes Tóth toth@dene@ @end|ng |rom kogentum@hu
Wed Mar 18 22:35:13 CET 2020



On 3/18/20 9:02 PM, Bert Gunter wrote:
> Untested in the absence of example data, but I think
> 
> combined <- do.call(rbind, lapply(ls2972, function(x)get(x)[[2]]))

Or if you have largish data, use rbindlist() from the data.table package:

combined <- data.table::rbindlist(
   lapply(ls2972, function(x) get(x)[[2]])
)

However, it seems you are on the wrong track when you create 2972 lists 
in your workspace. (Note: there are no "list files" objects in R. Lists 
are objects, not files.) You should have one list of 2972 lists each 
having 4 data.frames.

E.g.:

x <- list(
   list(
     data.frame(),
     data.frame(x = 1),
     data.frame(),
     data.frame()
   ),
   list(
     data.frame(),
     data.frame(x = 2),
     data.frame(),
     data.frame()
   ),
   list(
     data.frame(),
     data.frame(x = 3),
     data.frame(),
     data.frame()
   )
)
keep <- lapply(x, "[[", 2L)
combined <- data.table::rbindlist(keep)


HTH,
Denes


> 
> should do it.
> 
> 
> Bert Gunter
> 
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> 
> 
> On Wed, Mar 18, 2020 at 12:16 PM Yuan Chun Ding <ycding using coh.org> wrote:
> 
>> Hi R users,
>>
>> I generated 2972 list files in R, each list includes four data frame files
>> , file names for those list file are VNTR13576, VNTR14689, etc.  the second
>> data frame in each list has the same 11 column names, but different number
>> of rows.
>>
>> I can combine two dataframes by
>> list2972 <-ls(pat="VNTR.*.")
>> test <-rbind(get(list2972[16])[[2]],get(list2972[166])[[2]] )
>>
>> I tried to combine all 2972 data frames from those 2972 list files using
>> do.call or lapply function, but not successful.
>>
>> Can you help me?
>>
>> Thank you very much!
>>
>> Ding
>>
>> ----------------------------------------------------------------------
>> ------------------------------------------------------------
>> -SECURITY/CONFIDENTIALITY WARNING-
>>
>> This message and any attachments are intended solely for the individual or
>> entity to which they are addressed. This communication may contain
>> information that is privileged, confidential, or exempt from disclosure
>> under applicable law (e.g., personal health information, research data,
>> financial information). Because this e-mail has been sent without
>> encryption, individuals other than the intended recipient may be able to
>> view the information, forward it to others or tamper with the information
>> without the knowledge or consent of the sender. If you are not the intended
>> recipient, or the employee or person responsible for delivering the message
>> to the intended recipient, any dissemination, distribution or copying of
>> the communication is strictly prohibited. If you received the communication
>> in error, please notify the sender immediately by replying to this message
>> and deleting the message and any accompanying files from your system. If,
>> due to the security risks, you do not wish to receive further
>> communications via e-mail, please reply to this message and inform the
>> sender that you do not wish to receive further e-mail from the sender.
>> (LCP301)
>>
>> ______________________________________________
>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list