[R] 3 basic questions
Gabriel Rodrigues Alves Margarido
gramarga at carpa.ciagri.usp.br
Sun Sep 21 16:53:24 CEST 2003
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
More information about the R-help
mailing list