[R] How to loop through all the columns in dataframe

From: Felipe Carrillo <mazatlanmexico_at_yahoo.com>
Date: Sat, 15 Mar 2008 17:17:09 -0700 (PDT)


Hi:
Can anyone advice me on how to loop and perform a calculation through all the columns.
here's my data
xd<-
c(2.2024,2.4216,1.4672,1.4817,1.4957,1.4431,1.5676) pd<-
c(0.017046,0.018504,0.012157,0.012253,0.012348,0.011997,0.012825) td<- c(160524,163565,143973,111956,89677,95269,81558)  mydf<-data.frame(xd,pd,td)

 trans<-t(mydf)
 trans
 I have these values that I need to include while looping:
 varA<- 0.0000036084
 covAB<- (-0.0000013046)
 varB<- 0.00000052628
 After transposing my dataframe I need something like the following:
 varA + col1*covAB + col2*covAB + col1*col2*varB

  varA + col1*covAB + col3*covAB + col1*col3*varB
  varA + col1*covAB + col4*covAB + col1*col4*varB
  varA + col1*covAB + col5*covAB + col1*col5*varB
     and so on..
     then do it all over again but starting with col2
   varA + col2*covAB + col3*covAB + col2*col3*varB    varA + col2*covAB + col4*covAB + col2*col4*varB   varA + col2*covAB + col5*covAB + col2*col5*varB   then col3
  then col4 to col7
  This is easy to do in Excel but I wonder if there's a way to do it with R
  This is the dataframe I get while doing a loop with Excel(the values generated could bedifferent).Thanks
  xd	           pd	         td
3.82755E-07	26256108060	0.000315419
5.21641E-07	23111121852	0.000207228
5.19531E-07	17971624944	0.000208865
5.17464E-07	14395310748	0.000210484
5.25148E-07	15292960956	0.000204501
5.0703E-07	13092016392	0.000218615

. . .
4.04929E-07 23548943745 0.000224953 4.04492E-07 18312083140 0.00022673 4.04064E-07 14668018505 0.000228487 4.05656E-07 15582673985 0.000221992 4.01901E-07 13340034270 0.000237314
. . .
9.05372E-07 16118641188 0.00014896 8.97811E-07 12911066721 0.000150115 9.25924E-07 13716163737 0.000145848 8.59635E-07 11742149934 0.000155914
. . .
8.9031E-07 10039878212 0.0001513 9.1802E-07 10665936164 0.000146999 8.52681E-07 9130907448 0.000157145
. . .
9.10279E-07 8543438113 0.000148139 8.4587E-07 7313876766 0.000158363
. . .
8.71193E-07 7769949102 0.000153862

 Felipe D. Carrillo
  Fishery Biologist
  Department of the Interior
  US Fish & Wildlife Service
  California, USA



R-help_at_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. Received on Sun 16 Mar 2008 - 00:21:06 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 17 Mar 2008 - 04:30:22 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive