as.numeric(apply(haplo, 1 ,function(x) paste(x,collapse=""))) perhaps?

Kristin Kay Nicodemus wrote:
Hi all,
Hope someone can help me. I start out with a matrix called haplo with 600 rows and two columns. To start with, the elements of the matrix are character strings of 20 numbers. I then want to create separate objects, called ha1-ha600, that are the concatenated 20 + 20 numbers, as numeric. I am having no trouble doing anything except getting the index i to paste to the object ha(i) in some fashion. When I do substring(haplo[(i)...) it works fine, but I can't seem to create objects that are ha1 or ha2 etc., containing the 40 number row I just created in the loop. I've tried paste but I can't seem to get it to do the right thing.
For this example, nc=20
for (i in 1:600) {
tst<-substring(haplo[(i),1],1:nc,1:nc)
a1<-as.numeric(tst)
tst<-substring(haplo[(i),2],1:nc,1:nc)
a2<-as.numeric(tst)
ha<-append(a1,a2)
ha(i)<-ha # DOESN'T WORK
}
TIA,
Kristin Nicodemus


        [[alternative HTML version deleted]]

______________________________________________
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


______________________________________________ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to