0

I am trying to subset a portion of the the larger dataset (while still keeping the new sub-matrix inside the original dataframe).

The goal is to create an object that I can loop through and estimate many logistic regression models with (running through many different predictor variables all at once).

Trying to make the matrix to loop through. Then the other variables would be selected from the rest of the dataframe (rather than the sub-matrix that gets looped through).

I was hoping to use mapply. However, first I have to make the matrix. I want the matrix to have the names of the variables retained and all observations retained. Unless there is a way to do what I am describing without that. But this is what I have so far:

metabolite.names <- df[df$Anhydro_1.5_D_glucitolArea:df$ErythritolArea]

This syntax seems to retain observations, but not variable names. When I use the str function, this is what it returns

> str(metabolite.names)
 'data.frame':    22 obs. of  0 variables

When I use the following code, it seems to retain the variable names, but not the observations:

metabolite.names <- df[df$Anhydro_1.5_D_glucitolArea:df$ErythritolArea,]

results:

> str(metabolite.names)
 'data.frame':    0 obs. of  170 variables:

How can I retain both? I believe I can create a subset of colnames, but does that then work with the Mapply function? If it doesn't, what method would work with mapply. Or what looping method would go with creating a subset of colnames?

stephr
  • 71
  • 5

0 Answers0