[R] (no subject)

sumfleth at geographie.uni-kiel.de sumfleth at geographie.uni-kiel.de
Sat May 5 17:17:22 CEST 2007

Dear Mailing-List,
I think this is a newbie question. However, i would like to integrate a
loop in the function below. So that the script calculates for each
variable within the dataframe df1 the connecting data in df2. Actually it
takes only the first row. I hope that's clear. My goal is to apply the
function for each data in df1. Many thanks in advance. An example is as

df1 <-data.frame(b=c(1,2,3,4,5,5,6,7,8,9,10))
df2 <-data.frame(x=c(1,2,3,4,5), y=c(2,5,4,6,5), z=c(10, 8, 7, 9, 3))
myfun = function(yxz) (x + y)/(z * df1$b)
df1$goal <- apply(df2, 1, myfun)



More information about the R-help mailing list