I'm quite new in R.
I have a function that uses 3 data frames to generate reports (basically do.reports
does a couple does some calculation among the tables and merged them.
create_report = do_reports(df1, df2, df3)
ID = c("ID1", "ID2", "ID3")
size = c(2, 5, 4)
p = c(0.05, 0.1, 0.3)
var = c(0.3, 0.5, 1.2)
location = c("blood", "tissue", "blood")
df1 = data.frame(ID = ID , size= size, p = p)
df2 = data.frame(ID = ID , var = var)
df3 = data.frame(ID = ID , location = location)
The output of this consists in 2 different objects ( create_report[1]
, create_report[2]
)
#expected create_report[1]
create_report[1] = data.frame(ID = ID , location = location, size = size , p=p)
#expected create_report[2]
create_report[2] = data.frame(location = location, size = size , p=p, var=var)
However, I would like to use do_reports
row by row in df2 (something like create_report = do_reports(df1, df2[1,], df3)
, save the results independently and once finishes, merge all of them in a table.
What I've tried so far is:
for (i in seq_len(nrow(df2) {
create_report = do_reports(df1, df2, df3)
}
I know that using a loop over it could be very tedious, so I was wondering if someone in here could help me with this.
Thank you