title: Plot residuals in linear model for specific date
body: <p><strong>Edit:</strong> Took the first answer given and made a function for further use out of it, but not using the dplyr-package. Still, it builds heavily on the given answer, so thank you.</p>
  
  <pre><code>plot_one_day &lt;- function(LM,Day,DF) {Residuals&lt;-resid(LM)
  Filter=cbind(DF,Residuals)
  Filterdata= Filter[Filter$Time&gt;=paste(Day,"00:00:00") &amp; Filter$Time&lt;=paste(Day,"23:50:00"),]
  Filter_NARM=Filterdata[!is.na(Filterdata$Residuals),]
  plot(Residuals ~ Time, data=Filter_NARM, main=paste("Correlation for the",substr(Filter_NARM[1,1],1,10)),xlab="Time",
       xlim=range(Filterdata$Time), ylim=range(Filter_NARM$Residuals))
  abline(h=0, col="red")
  }
  
  plot_one_day(LM_1,"2015-05-07",MyData)
  </code></pre>
  
  <p>When you have a dataframe like this:  </p>
  
  <pre><code>start &lt;- as.POSIXct("2015-05-05 06:00:00", format="%Y-%m-%d %H:%M:%S")
  end   &lt;- as.POSIXct("2015-05-07 20:00:00", format= "%Y-%m-%d %H:%M:%S")
  Time=seq.POSIXt(start, end, by="10 min")
  
  MyData=data.frame(Time=Time,Rain=rep(0,(length(Time))),Rain_Binary=rep(0,(length(Time))),People=rep(0,(length(Time))))
  MyData[c(2:4,154:157,324:328),2]=5
  MyData$People=round(runif(length(Time),0,50), digits=0)
  
  for (Z in 1:nrow(MyData)) {Today= substr(MyData[Z,1], 1, 10)
  if(any(MyData$Rain[((MyData$Time&gt;= strptime(paste(Today, "06:30:00", sep = " "),format="%Y-%m-%d %H:%M:%S"))&amp;
                      (MyData$Time&lt;= strptime(paste(Today, "09:00:00", sep = " "),format="%Y-%m-%d %H:%M:%S")))]&gt;0)) {MyData$Rain_Binary[(MyData$Time&gt;=strptime(paste(Today, "06:30:00", sep = " "),format="%Y-%m-%d %H:%M:%S"))&amp;
                                                                                                                                           (MyData$Time&lt;= strptime(paste(Today, "20:00:00", sep = " "),format="%Y-%m-%d %H:%M:%S"))]=1
  }
  }
  MyData$Rain_Binary=as.factor(MyData$Rain_Binary)
  </code></pre>
  
  <p>And generate a linear model of it:   </p>
  
  <pre><code>LM_1 = lm(People ~ Time + Rain_Binary, data=MyData, na.action = na.exclude)
  </code></pre>
  
  <p>You check the residuals of it:  </p>
  
  <pre><code>plot(resid(LM_1) ~ c(1:dim(MyData)[1]), data=MyData, main="Correlation complete",xlab="Time")
  </code></pre>
  
  <p><em>Question:</em> How do I adress only one day in the dataframe against which the residuals are plotted? This here gives an error:</p>
  
  <pre><code>plot(resid(LM_1) ~ MyData$Time[substr(MyData$Time,1,10)==strptime("2015-05-06",format="%Y-%m-%d")], data=MyData, main="Correlation 1 Day \n 2015-09-03", xlab="Time")
  </code></pre>