Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A loop is not necessary here, if I understand your end goal. Instead, you can transform your dataset into an actual time-series dataset and plot the resulting data.</p> <p>Here's the sample data you supplied:</p> <pre><code>temp &lt;- read.table(header = TRUE, text = " ts1 ts2 ts3 ts4 1 6871 6855 6843 6870 2 6872 6858 6848 6872 3 6873 6861 6854 6874 4 6874 6865 6859 6877 5 6876 6868 6864 6879 6 6877 6871 6869 6881 7 6879 6875 6874 6883 8 6880 6878 6879 6886 9 6882 6881 6884 6888 10 6883 6884 6889 6890") </code></pre> <p>We'll imagine this data spans 1990 to 1999 and is yearly data.</p> <pre><code>temp.ts &lt;- ts(temp, start = 1990, end = 1999, frequency = 1) plot(temp.ts, plot.type = "single") </code></pre> <p>The result:</p> <p><img src="https://i.stack.imgur.com/a6OYW.png" alt="enter image description here"></p> <p>I would think this is the most efficient way to approach this. </p> <p>Another approach is to add in a variable for "year" and reshape your data from wide to long (but I'm not sure how that would work with 1000 time series variables). The basic approach would be something like:</p> <pre><code>temp$year &lt;- seq(1990, length.out=10) temp1 &lt;- reshape(temp, direction = "long", idvar="year", varying=names(temp)[grepl("ts", names(temp))], sep ="") plot(temp1$year, temp1$ts, type = "l") </code></pre> <p>There are other approaches (in particular using <code>lapply</code>, which will go through your <code>data.frame</code> by columns) that you might find useful.</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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