I am trying to using each row in a data frame as inputs to a function to process some data and then write the output to a csv file. As per the following example
myfunction <- function(X, Y, Z){
                       data <- read.csv("mydata.csv")
                       subsetedData <- subset(data, x=X & y=Y & z=Z, select=x:z)
                       write.csv(subsetedData, file="mycsvfile.csv")
                       }
apply(myXYZdata, MARGIN = 1, function(x1, x2, x3) myfunction(X, Y, Z))
I want to subset based on every row in the dataframe myXYZdata. However this does not appear to work or I am not fully understanding the correct usage of apply.
I know this can be done using a loop but would prefer not to do it that way.
Edit:
The purpose of this is that I have a large data file which I want to subset based on combinations of variables found in my data frame "myXYZdata" and store the results in new data files.
The large data file I want to subset is in the format.
date                      x   y  z    count          
1 2015-08-20 00:00:00.000 a   d  h    56
2 2015-08-26 00:00:00.000 b   e  h     4
3 2015-08-18 00:00:00.000 b   f  i     8
4 2015-09-03 00:00:00.000 c   e  l     32
5 2015-08-12 00:00:00.000 a   g  l     3