Re: [R] breaking a loop in R

2009-07-04 Thread NatsS

Hello,

Please could someone explain 

break and next??

Is there a way to break a loop that is not the innermost loop??

for example:
#=
dim A = 1000 x 3
dim B = 2000 x 3

for (a in 1:1000){
for (b in 1:2000){
 expr = intersect(A[a,1]:A[a,2],B[b,1]:B[b,2])
 if (!is.na(expr[1])){
 indx = which(expr[1] = A[,2])
 if (length(indx)  1){
for(c in 1:length(indx))
 X[a,1] = paste(.)
 .
 }else {
 X[a,1] = A[indx, 3]
 }
  } 
  ###BREAK - Here does not work
NEXT # am not sure if this is doing what I want it to??
  }
}  
#=

Any help and advice would be much appreciated!

Many Thanks,
NS 
-- 
View this message in context: 
http://www.nabble.com/breaking-a-loop-in-R-tp21322868p24325853.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Plot error

2009-05-28 Thread NatsS

Hello,

I am an R amateur.

I want to plot data such that the 3 time points(a,b,c) lie on the X-axis and
the values of these times points are on Y-axis for n samples (e.g.100).

So, I have an object x, dim 100 4, it is a dataframe (when checked the
class)
x = 
name   a   b  c
10.11  1.11   0.86
2   .  .   .
3   .  .   .
.
.
.
100

so when i say:

 plot(1:3, x[,2:4], type=l) - I get the error below

Error in xy.coords(x, y, xlabel, ylabel, log) : 
   (list) object cannot be coerced to type 'double'

However if I do:
 plot(1:3, x[1,2:4], type=l) -- It works for the 1st row, and each
 individual row BUT NOT ALL ROWS

Please could someone explain what is happening here?

I wonder if I need to use 'lines' for the remaining, BUT I have another
dataset y with same dimensions as x, which I want to plot on the same
graph/plot to see the difference between x and y.

Thanks,
NS
-- 
View this message in context: 
http://www.nabble.com/Plot-error-tp23761408p23761408.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.