1. The first row of x is all zeros so the condition in the while loop
is never satisfied causing it to test x[1,4]!=1 on the fourth iteration. The 4
is out of bounds. You might try:
types <- (rowSums(x)>0)+0
2.
x <- readLines(myfile)
strsplit(substring(x,8),split="")
3. same
--- Gabriel Rodrigues Alves Margarido <gramarga@carpa.ciagri.usp.br>
wrote:
I have 3 basic questions (sorry, but R is a bit new to me)
First)
The following code will work on C, but something happens with R:
> x<-c(0,1,1,0,0,1,0,0,1)
> dim(x)<-c(3,3)
> types<-numeric(3)
> for (i in 1:3) {
+ j<-1
+ while (x[i,j]!=1) j<-j+1
+ if (j==4) types[i]<-0
+ else types[i]<-1
+ }
Error: subscript out of bounds
Any ideas about what is wrong?
Second)
I have a data file like this:
*data1 HHHHHHHHAAAAAABBBBBB...
*data2 HHHHHHHAAAAAABBBBBBB...
When I use read.table, all the characters are read as one variable.
How can I put each of them into a different column? Besides, I want to
discard the labels *data1 and *data2.
Third)
If the same file is like this:
*data1 HHHHHHHHAAAA
AABBBBB...
*data2 HHHHHHHAAAAA
ABBBBBB...
Can I read it like the one on question 2 (each data represented by a
line)?
Thank you in advance
Gabriel Margarido
______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help