'How to change the names in the named numbers structure in R? [duplicate]
I am trying to change the names in the Named numbers. It's harder than I thought. Any suggestions?
set.seed(111)
y1.predict <- rnorm(12,3,1)
y1.n1 <- c(1000, 2000, 3000, 4000,0,0,0,0,1000,4000,3000,3000)
y1.n2 <- c(0,0,0,0,1000, 2000, 3000, 4000,4000,1000,2000,2000)
y2.predict <- rnorm(16,5,1)
y2.n1 <- c(1000, 2000, 3000, 4000,0,0,0,0,1000,4000,3000,3000,1000,0,2500,4000)
y2.n2 <- c(0,0,0,0,1000, 2000, 3000, 4000,4000,1000,2000,2000,0,4000,2500,0)
df1 <- data.frame(y1.predict, n1=y1.n1, n2=y1.n2)
df2 <- data.frame(y2.predict, n1=y2.n1, n2=y2.n2)
fit.1 <- lm(y1.predict ~ n1 + n2, df1)
fit.2 <- lm(y2.predict ~ n1 + n2, df2)
#
means <- c((coef(fit.1)['(Intercept)'] + coef(fit.1)['n1'])/coef(fit.1)['(Intercept)'], (coef(fit.2)['(Intercept)'] + coef(fit.2)['n2'])/coef(fit.2)['(Intercept)'])
(Intercept) (Intercept)
0.9999409 0.9999575
#Need to change it to
n1 n2
0.9999409 0.9999575
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
