_____________________________________________
#Reading columns (first one)
c.n1 <- 'xs1'
c1 <- with(xss, get(c.n1))
#Mean
mc1 <- mean (c1)
#Standard deviation
sdc1 <- sd(c1)
#Control Limits
L=3
uclc1 = mc1 + L*sdc1
lclc1 = mc1 - L*sdc1
I need an "if" inside a loop to do the following:
for (each column)
if (value in c1 < lclc1 | value in c1 > uclc1) {Count how many values are
outside the bounds}
And I need this process to be repeated to all columns.
2012/7/30 Rui Barradas <ruipbarradas at sapo.pt>
Hello,
Your code example doesn't make much sense, it needs decrypting. Let's see,
for(k in 1:length(c1)){
if(c1[k] < lcl | c1[k] > ucl) {do something}
}
If this is it, then you can completely avoid the loop:
i1 <- c1 < lcl | c1 > ucl # create an index vector
out.of.control <- c1[ i1 ] # save the values
When you say you have a column, is it a matrix column? data.frame?
Give a data example with
dput( head(myData, 20) ) # paste the output of this in a post
Hope this helps,
Rui Barradas
Em 29-07-2012 21:59, Wellington G. Silva escreveu:
Hi,
I'm Wellington from Brazil and I have the following issue:
I've been working on a project a for a while, and I'm having trouble in
using the loop (for)
I need to read a column (c1), and for each value of this column, I need to
check if it's within the control limits
So, I was trying to do this:
For (k in 1: c1)
If (c1< lcl1 | c1 > ucl1) {here I need to store the values outside the
limits)
I have 5 columns, need to do the same process in each one of them.
And later on I'm gonna concatenate these 5 vectors and calculate its mean
for an ARL project.
[[alternative HTML version deleted]]
______________________________**________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
PLEASE do read the posting guide http://www.R-project.org/**
posting-guide.html <http://www.R-project.org/posting-guide.html>
and provide commented, minimal, self-contained, reproducible code.