I got the confidence levels per variable in linear regression.I wanted to use the results for sorting variables so I kept the result set as a data frame. However when I tried to do an str()
function on one of the variables I got an error (written below).How can I store the result data set so I'll be able to work on it?
df <- read.table(text = "target birds wolfs
1 9 7
1 8 4
0 2 8
1 2 3 3
0 1 2
1 7 1
0 1 5
1 9 7
1 8 7
0 2 7
0 2 3
1 6 3
0 1 1
0 3 9
0 1 1 ",header = TRUE)
model<-lm(target~birds+wolfs,data=df)
confint(model)
2.5 % 97.5 %
(Intercept) -0.23133823 0.36256052
birds 0.10102771 0.18768505
wolfs -0.09698902 0.00812353
s<-as.data.frame(confint(model))
str(s$2.5%)
Error: unexpected numeric constant in "str(s$2.5"
2.5
and%
in order to match the exact column name. Trystr(s$`2.5 %`)
. Other than that, I would advise you to convert your column names to a proper column names usingnames(s) <- make.names(names(s))
data.frame
instead ofas.data.frame
,make.names
will be automatically applied. Trys <- data.frame(confint(model))
make.names
is inappropriate? There is also an example in the answers on how to use backticks in order to call inappropriate name in R. When I suggested this to the OP he seemed to be satisfied. I didn't mandate anything. Every dupe could have many additional answers, so you suggest we won't close anything as a dupe?