Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to repeat a variable down a list?
    primarykey
    data
    text
    <p>I have a field of semantic tags/semantic tag categories, along with a Source, Date, &amp; ID variables. I want to break out the semantic tag field into the respective tags/tag categories, then transpose the dataset. I have most of the code worked out, but am still stuck on getting the ID/Date/Source variables to list down the matrix I create from the tag categories/tags. An example of the data I start with (tab-delimited) is below:</p> <pre><code>ID Source Date Semantic Tags 1 thestate 2013-01-18 Person:elizabeth colbert-busch, Organization:congress 2 abcnews4 2013-04-03 PoliticalEvent:congressional race, Person:colbert busch, topicname:politics 3 Politics 2013-04-02 Person:mark sanford, Person:elizabeth colbert busch, Person:colbert busch, Organization:republican party </code></pre> <p>I want the data to look like a database format (also tab-delimited):</p> <pre><code>ID Source Date Tag Type Tag 1 thestate 2013-01-18 Person elizabeth colbert-busch 1 thestate 2013-01-18 Organization congress 2 abcnews 2013-04-03 Political event congressional race 2 abcnews 2013-04-04 Person colbert-busch 2 abcnews 2013-04-05 topicname politics 3 Politics 2013-04-02 person mark sanford 3 Politics 2013-04-03 person elizabeth colbert-busch 3 Politics 2013-04-04 organization republican party </code></pre> <p>I'm having no trouble separating the tag types &amp; tags (thnx @Tyler Rinker for help on that...), but when I am stuck on getting the ID, Source, &amp; Date variables to repeat listwise down the tag type/tag matrix that I create. Can anyone help? My code is below:</p> <pre><code>et3 &lt;- lapply(strsplit(as.character(et$Semantic.Tags), ","), function(x) gsub("^//s+|//s+$", "", x)) # break out semantic tags/tag type by comma et3 &lt;- lapply(et3, strsplit, ":(?!/)", perl=TRUE) # break on colon </code></pre> <p>The following lines of code, where I try to replicate the other three variables, is where I have problems:</p> <pre><code>Date &lt;- rep(et$Date, seq_along(et3), sapply(et3, length)) ID &lt;- rep(et$ID, seq_along(et3), sapply(et3, length)) # Note that if I don't use "et$ID", the IDs replicate without issue... </code></pre> <p>...And likewise for variable Source. The warning msg I receive is: <code>In rep(et$Date, seq_along(et3), sapply(et3, length)): first element used of 'length.out' argument.</code> And only the first value appears in the output. The same problem happens if I first bind the et3 lists as a matrix. Can anyone help on repeating the variables down a matrix/list? I have also tried to use a transpose command, but I don't know how to treat the tags that I turned into lists.</p> <p>thanks for anyone's help.</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