I am working on a data frame which I named 'data'
I need to calculate the weighted mean age for each study, that is to say for each row. I can use the following set of functions:
weighted.mean(x=data[1,7:8],w=data[1,5:6])
weighted.mean(x=data[1,7:8],w=data[1,5:6])
weighted.mean(x=data[2,7:8],w=data[2,5:6])
weighted.mean(x=data[3,7:8],w=data[3,5:6])
weighted.mean(x=data[4,7:8],w=data[4,5:6])
weighted.mean(x=data[5,7:8],w=data[5,5:6])
weighted.mean(x=data[6,7:8],w=data[6,5:6])
Is it possible to create some kind of loop so that I don't have to write six commands but just one and then attach the results as a new column in my data frame ? Many thanks for your help