[R] Question on getting a data from dataframe

From: Stephen Opiyo <sopiyo_at_unlserve.unl.edu>
Date: Fri 30 Jul 2004 - 01:56:18 EST


I am working with amino acid sequences changing each letter to numbers.I have a data from acf transformation called Zm as shown below. I would like to get Indices D1 to D10 and then create F1 to F10 as indicated below. Is there anyway I can do that in R without typing each of them one by one. For example to get D1 to D3, I have to type D1<-c(Zm[[1]])[1][[1]], D2<-c(Zm[[2]])[1][[1]], and D3<-c(Zm[[3]])[1][[1]].     

 This is Zm was calculated.
 ReadZm<-read.table("C:\\Documents and Settings\\stephen\\Desktop\\practice\\Ft.dat&quot;, header=TRUE)  Zm<-by(scale(ReadZm[, 3:5],center=FALSE, scale=TRUE),ReadZm$GI, acf, = lag.max=5, type="covariance", plot=FALSE)  

Zm
INDICES: D1
Autocovariances of series 'data[x, ]', by lag

, , Z1

 Z1                  Z2                  Z3                 
  1.0038341836 (  0) -0.0689672193 (  0)  0.1638605166 (  0)
 -0.0484984679 (  1) -0.1884834898 ( -1)  0.1599671586 ( -1)
  0.1129146146 ( 2) -0.0268675914 ( -2) 0.0604863049 ( -2)   0.0580622445 ( 3) 0.0176879067 ( -3) 0.0511021407 ( -3)

Zm
INDICES: D2
Autocovariances of series 'data[x, ]', by lag

, , Z1

 Z1                  Z2                  Z3                 
  1.076612e+00 (  0)  3.475059e-02 (  0)  1.728981e-01 (  0)
 -2.639058e-04 ( 1) 2.919360e-03 ( -1) -5.340469e-03 ( -1)   2.669045e-02 ( 2) -8.738303e-02 ( -2) -6.066240e-02 ( -2)

Zm
INDICES: D3
Autocovariances of series 'data[x, ]', by lag

, , Z1

 Z1                  Z2                  Z3                 
  1.0583627071 (  0)  0.0396194354 (  0)  0.1507399860 (  0)
  0.0016303943 (  1)  0.0025233219 ( -1)  0.0354695276 ( -1)
  0.0093683974 ( 2) -0.0666452362 ( -2) -0.0721539962 ( -2)   0.0482982100 ( 3) -0.0211955002 ( -3) 0.0740133158 ( -3)

etc.

I would like to convert those indices into arrays as indicated below by typing each index D1, D2,.....D10. Is there a way of doing that in R without going through each index? My final results should appear like example of figure 1 below.

    D1<-c(Zm[[1]])[1][[1]]
    D2<-c(Zm[[2]])[1][[1]]
    D3<-c(Zm[[3]])[1][[1]]
    D4<-c(Zm[[4]])[1][[1]]
    D5<-c(Zm[[5]])[1][[1]]
    D6<-c(Zm[[6]])[1][[1]]
    D7<-c(Zm[[7]])[1][[1]]
    D8<-c(Zm[[8]])[1][[1]]
    D9<-c(Zm[[9]])[1][[1]]

    D10<-c(Zm[[10]])[1][[1]]     

    To calculate F1 to F10 see below.     

    F1<-data.frame<-c(D1)
    F2<-data.frame<-c(D2)
    F3<-data.frame<-c(D3)
    F4<-data.frame<-c(D4)
    F5<-data.frame<-c(D5)
    F6<-data.frame<-c(D6)
    F7<-data.frame<-c(D7)
    F8<-data.frame<-c(D8)
    F9<-data.frame<-c(D9)

    F10<-data.frame<-c(D10)

  K<-rbind(F1,F2,F3,F4,F5,F6,F7,F8,F9,F10)

Figure 1. K

D1   0.0438961122 -0.0850376026  0.003703249 -0.045145163 -0.0137549764
D2   0.0858789555  0.1359138805  0.142618579  0.181216290  0.2144693206
D3  -0.0120998969  0.0538759994  0.043675137  0.001780804  0.0357002270
D4   0.0576657536  0.0255354998 -0.001225369  0.021486156  0.0371668239
D5  -0.0347536925  0.0148086592  0.029135976  0.066354175 -0.0069727461
D6   0.0546508768  0.0293732170 -0.049859976  0.204040093  0.0611271659
D7   0.0507488987  0.1765004194  0.081786138  0.105454843  0.0077602850
D8  -0.0297705333  0.0094467070  0.019988517  0.055050705  0.0002062495
D9   0.0791272355  0.0320509961  0.073237929  0.036325332  0.0302841389
D10  0.0000995983  0.0646743929  0.044791169  0.010257411  0.0478312766
    
    
    

Sincerely,     

Stephen Opiyo

        [[alternative HTML version deleted]]



R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Fri Jul 30 02:06:39 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:55:21 EST