My dataframe looks like this
df = structure(list(Date_Time_GMT_3 = structure(c(1625025600, 1625026500,1625027400, 1625028300, 1625029200, 1625030100),
class = c("POSIXct", "POSIXt"), tzone = "EST"),
X20676887_X2LH_S = c(26.879, 26.781,26.683, 26.585, 26.488, 26.39),
X20819831_11LH_S = c(26.39, 26.292, 26.195, 26.195, 26.097, 26),
X20822214_X4LH_S = c(26.39, 26.292,26.292, 26.195, 26.097, 26),
LH27_20822244_U_Stationary = c(23.388, 23.292, 23.292, 23.196, 23.196, 23.196)),
row.names = 2749:2754, class = "data.frame")
and I'm trying to get the linear regression equations and R squared values for all columns where the column with the string
"Stationary"
in it will always be on the x-axis.
so far I can perform the linear regression for 1 column against the "stationary"
column
model = lm(df$LH27_20822244_U_Stationary ~
df$X20822214_X4LH_S, df)
and when I use
summary(model)
afterwards it gives me some values I would like in a dataframe (i.e R squared
, Estimate Std.
, Std. Error
, Pr(>|t|)
) but 2 things I need to help with are:
- I still need the regression equation for each column that doesn't have
stationary
in the name - I need these values for each of the columns that don't have
stationary
in it's name, and I need that to be a dataframe that looks like so...
Logger_ID Reg_equation R_Squared Estimate_Std. Std_Error Pr_t..
<chr> <int> <int> <int> <int> <int>
1 X20676887_X2LH_S NA NA NA NA NA
2 X20819831_11LH_S NA NA NA NA NA
3 X20822214_X4LH_S NA NA NA NA NA