<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"Lucida Console";
        panose-1:2 11 6 9 4 5 4 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
p.gmail-m8490675542257718255gmail-m6006289437679071460gmail-p2, li.gmail-m8490675542257718255gmail-m6006289437679071460gmail-p2, div.gmail-m8490675542257718255gmail-m6006289437679071460gmail-p2
        {mso-style-name:gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-p2;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
span.gmail-m8490675542257718255gmail-m6006289437679071460gmail-s4
        {mso-style-name:gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s4;}
span.gmail-m8490675542257718255gmail-m6006289437679071460gmail-s5
        {mso-style-name:gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s5;}
p.gmail-m8490675542257718255gmail-m6006289437679071460gmail-p1, li.gmail-m8490675542257718255gmail-m6006289437679071460gmail-p1, div.gmail-m8490675542257718255gmail-m6006289437679071460gmail-p1
        {mso-style-name:gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-p1;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
span.gmail-m8490675542257718255gmail-m6006289437679071460gmail-s6
        {mso-style-name:gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s6;}
span.gmail-m8490675542257718255gmail-m6006289437679071460gmail-s1
        {mso-style-name:gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s1;}
span.gmail-m8490675542257718255gmail-m6006289437679071460gmail-s2
        {mso-style-name:gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-s2;}
p.gmail-m8490675542257718255gmail-m6006289437679071460gmail-p3, li.gmail-m8490675542257718255gmail-m6006289437679071460gmail-p3, div.gmail-m8490675542257718255gmail-m6006289437679071460gmail-p3
        {mso-style-name:gmail-m_8490675542257718255gmail-m_6006289437679071460gmail-p3;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
p.m4054072884049806692gmail-m6006289437679071460gmail-p1, li.m4054072884049806692gmail-m6006289437679071460gmail-p1, div.m4054072884049806692gmail-m6006289437679071460gmail-p1
        {mso-style-name:m_4054072884049806692gmail-m_6006289437679071460gmail-p1;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
span.m4054072884049806692gmail-m6006289437679071460gmail-s1
        {mso-style-name:m_4054072884049806692gmail-m_6006289437679071460gmail-s1;}
span.m4054072884049806692gmail-m6006289437679071460gmail-s2
        {mso-style-name:m_4054072884049806692gmail-m_6006289437679071460gmail-s2;}
span.m4054072884049806692gmail-m6006289437679071460gmail-s3
        {mso-style-name:m_4054072884049806692gmail-m_6006289437679071460gmail-s3;}
p.m4054072884049806692gmail-m6006289437679071460gmail-p2, li.m4054072884049806692gmail-m6006289437679071460gmail-p2, div.m4054072884049806692gmail-m6006289437679071460gmail-p2
        {mso-style-name:m_4054072884049806692gmail-m_6006289437679071460gmail-p2;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
span.m4054072884049806692gmail-m6006289437679071460gmail-s4
        {mso-style-name:m_4054072884049806692gmail-m_6006289437679071460gmail-s4;}
span.m4054072884049806692gmail-m6006289437679071460gmail-s5
        {mso-style-name:m_4054072884049806692gmail-m_6006289437679071460gmail-s5;}
span.m4054072884049806692gmail-m6006289437679071460gmail-s6
        {mso-style-name:m_4054072884049806692gmail-m_6006289437679071460gmail-s6;}
p.m4054072884049806692gmail-m6006289437679071460gmail-p3, li.m4054072884049806692gmail-m6006289437679071460gmail-p3, div.m4054072884049806692gmail-m6006289437679071460gmail-p3
        {mso-style-name:m_4054072884049806692gmail-m_6006289437679071460gmail-p3;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
span.EmailStyle35
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
span.EmailStyle36
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Hi Thomas,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Thank you again for your help.  It appears, however, that I am still stuck.  When I got back to my computer to try your suggested solutions, I did not get the
 expected results.  To help with the diagnosis of the problem, I have written an example below that can be run to reproduce the problems.  My attempts at using loops are at the end of the code .<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Jeremy<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">library(TraMineR)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">library(WeightedCluster)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">data(mvad)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">mvad.alphabet <- c("employment", "FE", "HE", "joblessness", "school", "training")<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">mvad.labels <- c("Employment", "Further Education", "Higher Education", "Joblessness", "School", "Training")<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">mvad.scodes <- c("EM", "FE", "HE", "JL", "SC", "TR")<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">mvadseq <- seqdef(mvad[, 17:86], alphabet = mvad.alphabet, states = mvad.scodes, labels = mvad.labels, weights = mvad$weight, xtstep = 6)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">#Defining the custom cost matrix<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">subm.custom <- matrix(<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">    c(0, 1, 1, 2, 1, 1,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">      1, 0, 1, 2, 1, 2,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">      1, 1, 0, 3, 1, 2,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">      2, 2, 3, 0, 3, 1,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">      1, 1, 1, 3, 0, 2,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">      1, 2, 2, 1, 2, 0),<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">    nrow = 6, ncol = 6, byrow = TRUE)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">#Compute the OM dissimilarities<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">mvaddist1.0 <- seqdist(mvadseq, method = "OM", indel = 1.0, sm = subm.custom)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">mvaddist1.5 <- seqdist(mvadseq, method = "OM", indel = 1.5, sm = subm.custom)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">mvaddist2.0 <- seqdist(mvadseq, method = "OM", indel = 2.0, sm = subm.custom)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">#obtain a series of cluster solutions<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">pamclust1.0 <- wcKMedRange(mvaddist1.0, kvals = 2:10, weights = mvad$weight)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">pamclust1.5 <- wcKMedRange(mvaddist1.5, kvals = 2:10, weights = mvad$weight)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">pamclust2.0 <- wcKMedRange(mvaddist2.0, kvals = 2:10, weights = mvad$weight)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">#print statistics for the various solutions<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">round(pamclust1.0$stats[,c("ASW", "HC", "R2", "PBC", "HG")],3)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">round(pamclust1.5$stats[,c("ASW", "HC", "R2", "PBC", "HG")],3)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">round(pamclust2.0$stats[,c("ASW", "HC", "R2", "PBC", "HG")],3)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">#plot the statistics for the various solutions<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">plot(pamclust1.0, stat=c("ASW","HC", "R2", "PBC", "HG"), legendpos="topright", norm="zscore")<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">  title(main="pamclust1.0")<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">plot(pamclust1.5, stat=c("ASW","HC", "R2", "PBC", "HG"), legendpos="topright", norm="zscore")<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">  title(main="pamclust1.5")<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">plot(pamclust2.0, stat=c("ASW","HC", "R2", "PBC", "HG"), legendpos="topright", norm="zscore")<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">  title(main="pamclust2.0")<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">############<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">#Many of the steps above involve a good bit of repetition.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">#I would rather do some of them with a loop, but all of my attempts below fail<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">############<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">#print statistics using a loop - attempt 1<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">indels1 <- list(pamclust1.0$stats, pamclust1.5$stats, pamclust2.0$stats)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">for (i in indels1){<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">  round(i[,c("ASW", "HC", "R2", "PBC", "HG")],3)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">}<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">#print statistics using a loop - attempt 2<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">indels2 <- list(1.0, 1.5, 2.0)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">for (i in indels2){<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">  round(get(paste0("pamclust",i,"$stats"))[,c("ASW", "HC", "R2", "PBC", "HG")],3)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">}<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">#plot statistics using a loop - attempt 1<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">indels3 <- list(pamclust1.0, pamclust1.5, pamclust2.0)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">for (i in indels3){<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">  plot(i, stat=c("ASW","HC", "R2", "PBC", "HG"), legendpos="topright", norm="zscore")<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">    title(main=i)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">}<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"> 
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> traminer-users-bounces@lists.r-forge.r-project.org [mailto:traminer-users-bounces@lists.r-forge.r-project.org]
<b>On Behalf Of </b>thomas collas<br>
<b>Sent:</b> Saturday, October 8, 2016 8:29 AM<br>
<b>To:</b> Users questions <traminer-users@lists.r-forge.r-project.org><br>
<b>Subject:</b> Re: [Traminer-users] loop for plotting quality statistics from wcKMedRange<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">Sure, you can use the pdf() function before the par() one. As quartz(), pdf() allows to define the dimensions of the window. Instead of par(), the layout() function is great too to divide the window into several plots. The pdf() file is
 produced while R meets the dev.off() line after the commands generating the plots, the axes, and so on. <o:p></o:p></p>
<div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-p2"><span style="font-size:9.5pt">pdf(file="working_directory/plots.pdf", height=, etc.)<o:p></o:p></span></p>
<p class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-p2"><span style="font-size:9.5pt">par(<span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s4">mfrow</span>=c(<span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s5">1</span>,<span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s5">2</span>))<o:p></o:p></span></p>
<p class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-p1"><span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s6"><span style="font-size:9.5pt">for</span></span><span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s1"><span style="font-size:9.5pt"> </span></span><span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s2"><span style="font-size:9.5pt">(</span></span><span style="font-size:9.5pt">i<span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s1"> </span><span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s6">in</span><span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s1"> </span>stats<span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s2">)</span><span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s1"> </span><span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s2">{</span><o:p></o:p></span></p>
<p class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-p3"><span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s2"><span style="font-size:9.5pt">  plot(</span></span><span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s4"><span style="font-size:9.5pt">i</span></span><span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s2"><span style="font-size:9.5pt">,</span></span><span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s1"><span style="font-size:9.5pt"> </span></span><span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s4"><span style="font-size:9.5pt">stat</span></span><span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s2"><span style="font-size:9.5pt">=c(</span></span><span style="font-size:9.5pt">"ASW"<span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s2">,</span>"HC"<span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s2">,</span><span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s1"> </span>"R2"<span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s2">,</span><span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s1"> </span>"PBC"<span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s2">,</span><span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s1"> </span>"HG"<span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s2">),</span><span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s1"> </span><span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s4">legendpos</span><span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s2">=</span>"topright"<span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s2">,</span><span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s1"> </span><span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s4">norm</span><span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s2">=</span>"zscore"<span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s2">)</span><o:p></o:p></span></p>
<p class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-p1"><span style="font-size:9.5pt"> <span class="gmail-m8490675542257718255gmail-m6006289437679071460gmail-s2">}</span><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal">dev.off()<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<p class="MsoNormal">Best,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">thomas<o:p></o:p></p>
</div>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">2016-10-08 14:09 GMT+02:00 Reynolds, Jeremy E <<a href="mailto:reyno113@purdue.edu" target="_blank">reyno113@purdue.edu</a>>:<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal">Thank you Thomas!  It is amazing how many things a novice user can mess up in just a few lines. Loops and the apply functions seem to be a perenniaI source of confusion in R.<o:p></o:p></p>
</div>
<div id="m_4054072884049806692AppleMailSignature">
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div id="m_4054072884049806692AppleMailSignature">
<p class="MsoNormal">I was hoping to save the plots in a single file (perhaps PDF?).  Do you have any additional tips for that?<o:p></o:p></p>
</div>
<div id="m_4054072884049806692AppleMailSignature">
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div id="m_4054072884049806692AppleMailSignature">
<p class="MsoNormal">Thanks<o:p></o:p></p>
</div>
<div id="m_4054072884049806692AppleMailSignature">
<p class="MsoNormal">Jeremy<o:p></o:p></p>
</div>
<div id="m_4054072884049806692AppleMailSignature">
<p class="MsoNormal"><br>
Sent from my iPhone<o:p></o:p></p>
</div>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><br>
On Oct 8, 2016, at 2:10 AM, thomas collas <<a href="mailto:thomas.collas@gmail.com" target="_blank">thomas.collas@gmail.com</a>> wrote:<o:p></o:p></p>
</div>
</div>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div>
<div>
<div>
<p class="MsoNormal">Dear Jeremy, <o:p></o:p></p>
<div>
<p class="MsoNormal">That should work if you change 3 things :<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">- the first problem is your stats object, which is a character vector, not a list of objects, you can't plot a character string.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">- the second problem is the "x" in the plot function. If i is a component and not an attribute of stats, you can't index stats with i.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">- the third smaller problem is that you have to ask R to print two plots. If it is only for visualization, you can use the mfrow argument in the par() function.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">After having created the two objects you want to plot, this code should work :<o:p></o:p></p>
</div>
<div>
<p class="m4054072884049806692gmail-m6006289437679071460gmail-p1">stats<span class="m4054072884049806692gmail-m6006289437679071460gmail-s1"> </span><span class="m4054072884049806692gmail-m6006289437679071460gmail-s2"><-</span><span class="m4054072884049806692gmail-m6006289437679071460gmail-s1"> </span><span class="m4054072884049806692gmail-m6006289437679071460gmail-s2">list(</span>pamomf2i5q.w<span class="m4054072884049806692gmail-m6006289437679071460gmail-s2">,</span><span class="m4054072884049806692gmail-m6006289437679071460gmail-s3"> </span>pamwardomf2i5q.w<span class="m4054072884049806692gmail-m6006289437679071460gmail-s2">)</span><o:p></o:p></p>
<p class="m4054072884049806692gmail-m6006289437679071460gmail-p2">par(<span class="m4054072884049806692gmail-m6006289437679071460gmail-s4">mfrow</span>=c(<span class="m4054072884049806692gmail-m6006289437679071460gmail-s5">1</span>,<span class="m4054072884049806692gmail-m6006289437679071460gmail-s5">2</span>))<o:p></o:p></p>
<p class="m4054072884049806692gmail-m6006289437679071460gmail-p1"><span class="m4054072884049806692gmail-m6006289437679071460gmail-s6">for</span><span class="m4054072884049806692gmail-m6006289437679071460gmail-s1"> </span><span class="m4054072884049806692gmail-m6006289437679071460gmail-s2">(</span>i<span class="m4054072884049806692gmail-m6006289437679071460gmail-s1"> </span><span class="m4054072884049806692gmail-m6006289437679071460gmail-s6">in</span><span class="m4054072884049806692gmail-m6006289437679071460gmail-s1"> </span>stats<span class="m4054072884049806692gmail-m6006289437679071460gmail-s2">)</span><span class="m4054072884049806692gmail-m6006289437679071460gmail-s1"> </span><span class="m4054072884049806692gmail-m6006289437679071460gmail-s2">{</span><o:p></o:p></p>
<p class="m4054072884049806692gmail-m6006289437679071460gmail-p3"><span class="m4054072884049806692gmail-m6006289437679071460gmail-s2">  plot(</span><span class="m4054072884049806692gmail-m6006289437679071460gmail-s4">i</span><span class="m4054072884049806692gmail-m6006289437679071460gmail-s2">,</span><span class="m4054072884049806692gmail-m6006289437679071460gmail-s1"> </span><span class="m4054072884049806692gmail-m6006289437679071460gmail-s4">stat</span><span class="m4054072884049806692gmail-m6006289437679071460gmail-s2">=c(</span>"ASW"<span class="m4054072884049806692gmail-m6006289437679071460gmail-s2">,</span>"HC"<span class="m4054072884049806692gmail-m6006289437679071460gmail-s2">,</span><span class="m4054072884049806692gmail-m6006289437679071460gmail-s1"> </span>"R2"<span class="m4054072884049806692gmail-m6006289437679071460gmail-s2">,</span><span class="m4054072884049806692gmail-m6006289437679071460gmail-s1"> </span>"PBC"<span class="m4054072884049806692gmail-m6006289437679071460gmail-s2">,</span><span class="m4054072884049806692gmail-m6006289437679071460gmail-s1"> </span>"HG"<span class="m4054072884049806692gmail-m6006289437679071460gmail-s2">),</span><span class="m4054072884049806692gmail-m6006289437679071460gmail-s1"> </span><span class="m4054072884049806692gmail-m6006289437679071460gmail-s4">legendpos</span><span class="m4054072884049806692gmail-m6006289437679071460gmail-s2">=</span>"topright"<span class="m4054072884049806692gmail-m6006289437679071460gmail-s2">,</span><span class="m4054072884049806692gmail-m6006289437679071460gmail-s1"> </span><span class="m4054072884049806692gmail-m6006289437679071460gmail-s4">norm</span><span class="m4054072884049806692gmail-m6006289437679071460gmail-s2">=</span>"zscore"<span class="m4054072884049806692gmail-m6006289437679071460gmail-s2">)</span><o:p></o:p></p>
<p class="m4054072884049806692gmail-m6006289437679071460gmail-p1"> <span class="m4054072884049806692gmail-m6006289437679071460gmail-s2">}</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Best,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">thomas<o:p></o:p></p>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<div>
<p class="MsoNormal">2016-10-08 4:41 GMT+02:00 Reynolds, Jeremy E <<a href="mailto:reyno113@purdue.edu" target="_blank">reyno113@purdue.edu</a>>:<o:p></o:p></p>
</div>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Dear TraMineR Users,<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">I would like to loop through many sets of clustering results produced with wcKMedRange and produce a plot for each one.  Without the loop, the code would look like this:<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">plot(pamomf2i5q.w, stat=c("ASWw","HC", "R2", "PBC", "HG"), legendpos="topright", norm="zscore")<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">plot(pamwardomf2i5q.w, stat=c("ASWw","HC", "R2", "PBC", "HG"), legendpos="topright", norm="zscore")<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">When I try to put this in a loop, I get the error messages below suggesting that R is expecting a y value in the plot command.  Is there something wrong with my loop that is causing
 this problem?<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Thanks,<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Jeremy<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;line-height:11.25pt;background:white;word-break:break-all">
<span style="font-size:10.0pt;font-family:"Lucida Console";color:blue">> stats <- c("pamomf2i5q.w", "pamwardomf2i5q.w")</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;line-height:11.25pt;background:white;word-break:break-all">
<span style="font-size:10.0pt;font-family:"Lucida Console";color:blue">> for (i in unique(stats)) {</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;line-height:11.25pt;background:white;word-break:break-all">
<span style="font-size:10.0pt;font-family:"Lucida Console";color:blue">+   plot(stats[i], stat=c("ASW","HC", "R2", "PBC", "HG"), legendpos="topright", norm="zscore")</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;line-height:11.25pt;background:white;word-break:break-all">
<span style="font-size:10.0pt;font-family:"Lucida Console";color:blue">+ }</span><o:p></o:p></p>
</div>
</div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;background:#E5E5E5;word-break:break-all">
<image001.png><span style="font-size:10.0pt;font-family:"Lucida Console";color:black"> Show Traceback</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;background:#E5E5E5;word-break:break-all">
<span style="font-size:10.0pt;font-family:"Lucida Console";color:black"> Rerun with Debug</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;line-height:11.25pt;background:#E5E5E5;word-break:break-all">
<span style="font-size:10.0pt;font-family:"Lucida Console";color:#C5060B">Error in plot.window(...) : need finite 'ylim' values</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;line-height:11.25pt;background:white;word-break:break-all">
<span style="font-size:10.0pt;font-family:"Lucida Console";color:#C5060B">In addition: Warning messages:</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;line-height:11.25pt;background:white;word-break:break-all">
<span style="font-size:10.0pt;font-family:"Lucida Console";color:#C5060B">1: In min(x) : no non-missing arguments to min; returning Inf</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;line-height:11.25pt;background:white;word-break:break-all">
<span style="font-size:10.0pt;font-family:"Lucida Console";color:#C5060B">2: In max(x) : no non-missing arguments to max; returning -Inf</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;line-height:11.25pt;background:white;word-break:break-all">
<span style="font-size:10.0pt;font-family:"Lucida Console";color:#C5060B">3: In plot.window(...) : "stat" is not a graphical parameter</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;line-height:11.25pt;background:white;word-break:break-all">
<span style="font-size:10.0pt;font-family:"Lucida Console";color:#C5060B">4: In plot.window(...) : "legendpos" is not a graphical parameter</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;line-height:11.25pt;background:white;word-break:break-all">
<span style="font-size:10.0pt;font-family:"Lucida Console";color:#C5060B">5: In plot.window(...) : "norm" is not a graphical parameter</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><br>
_______________________________________________<br>
Traminer-users mailing list<br>
<a href="mailto:Traminer-users@lists.r-forge.r-project.org" target="_blank">Traminer-users@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/traminer-users" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/traminer-users</a><o:p></o:p></p>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</blockquote>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal">_______________________________________________<br>
Traminer-users mailing list<br>
<a href="mailto:Traminer-users@lists.r-forge.r-project.org" target="_blank">Traminer-users@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/traminer-users" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/traminer-users</a><o:p></o:p></p>
</div>
</blockquote>
</div>
<p class="MsoNormal"><br>
_______________________________________________<br>
Traminer-users mailing list<br>
<a href="mailto:Traminer-users@lists.r-forge.r-project.org">Traminer-users@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/traminer-users" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/traminer-users</a><o:p></o:p></p>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</body>
</html>