Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to properly declare and fill columns within a database-like structure when starting with a data.frame with one column
    primarykey
    data
    text
    <p>I am not an R newbie and also not a pro. I can not solve nicely this problem.</p> <p>Assume this structure: surveys is a data frame with the following structure</p> <pre><code>surveys=data.frame(id=c(1L,3L,5L)) surveys </code></pre> <p>There are 3 survey IDs but assume I have a long list of 2000+ surveys</p> <p>There also is a web which can get me an XML with some more info about the survey. E.g., how many people participated, when it was done. The full structure looks like this:</p> <pre><code>survey -1 survey_id -2 number of respondents -3 names of respondents - (each respondent has a first name and last name) -4 when_done -5 when_received </code></pre> <p>I want to add rows and dimensions to the surveys "data.frame" or (or list of lists) which will be results of the web service call</p> <p>So I do a loop like this</p> <pre><code>for (1:nrow(surveys)) { current=surveys$id[i] webout=getWebServiceResults(current) this will outputs a list of variables such as when_done, when_received) and now I want to store results of the webservice calls into the surveys structure by adding correct rows to surveys) } </code></pre> <p>Assume that the webservice output is list and I can get when_received data by using <code>webout[[5]]</code></p> <ol> <li><p>Now how can I prior that loop, properly declare some new columns and declare their type as ISODate for example. Number of respondents as integer.</p> <p>I am used to work with databases. So I would just say alter table, add column with data type Date.</p> <p>How do I do it in R?</p></li> <li><p>Also, how can put into survey object a substructure of differing length per survey (Person - with sub-fields like First_name and Last_name.</p> <p>In a database, I would create a separate linkage table with survey_ID and participant_ID and a another table with Participant_id and columns First_name and Last_name.</p> <p>But is there an elegant way in R to do this (e.g., data_frame column Participant is some sort of deeper structure? Do I have to stop using data.frame and convert surveys to a list?</p></li> </ol>
    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