86294

How to dynamically assign names to dataframes?

Question:

I am trying to do a web search that will return several data frames (of different sizes), based on zip codes. I would like to dump each search result into a data frame named after the zip code.

require(XML) zip <- c(zip1, zip2, zip3, etc) k <-4 #index for the table that needs to be retrieved for (i in 1:length(zip)) { url <- paste(text1, zip[i], text2, sep="") resultsdataframe <- data.frame (readHTMLTable(url), which = k) }

So my question is: how can I get different names for resultsdataframe, each named dynamically from zip[i]? Many thanks.

Answer1:

You can use sapply , it will assign names for you.

sapply(zip, function(x) { url <- paste(text1, x, text2, sep="") data.frame (readHTMLTable(url), which = k) }

For example

zip <- paste('zip',1:5, sep ='') ll <- sapply(zip, function(x) { data.frame () }) ll $zip1 data frame with 0 columns and 0 rows $zip2 data frame with 0 columns and 0 rows ....

No need to use assign. You can access your list like this

ll[['zip1']] data frame with 0 columns and 0 rows

Recommend

  • Download and save file from http server using .Net Socket
  • What does “t” refer to in this SQL?
  • CERN ROOT exporting data to plain text
  • wxPython: displaying multiple widgets in same frame
  • rspec simple example getting error on request variable in integration test
  • Django simple Captcha “No module named fields” error
  • How to attach a node.js readable stream to a Sendgrid email?
  • Play WS (2.2.1): post/put large request
  • Why does access(2) check for real and not effective UID?
  • Exception “firebase.functions() takes … no argument …” when specifying a region for a Cloud Function
  • R - Combining Columns to String Based on Logical Match
  • Javascript simulate pressing enter in input box
  • Spray.io: When (not) to use non-blocking route handling?
  • How reduce the height of an mschart by breaking up the y-axis
  • How to add date and time under each post in guestbook in google app engine
  • SSO with signing and signature validation doesn't work
  • Deserializing XML into class C#
  • How to show dropdown in excel using jrxml (jasper api)?
  • Importing jscolor library in angular 2
  • Release, debug version and Authorization Google?
  • Websockets service method fails during R startup
  • Alternatives to the OPTIONAL fallback SPARQL pattern?
  • How to get next/previous record number?
  • Apache 2.4 - remove | delete | uninstall
  • Is there a mandatory requirement to switch app.yaml?
  • Proper way to use connect-multiparty with express.js?
  • Acquiring multiple attributes from .xml file in c#
  • Trying to get generic when generic is not available
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • embed rChart in Markdown
  • How to get Windows thread pool to call class member function?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • How can I remove ASP.NET Designer.cs files?
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Unable to use reactive element in my shiny app
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal