Reputation: 31
In R, some functions expect the function parameters to be in quotes, like this:
summarySE(xx, measurevar= "X1F1", groupvars="genotype",na.rm=TRUE)
others seem happy with the same parameter without ", like this:
aov(data=xx,X1F1~genotype)
How can I convert from a string like "X1F1" to the X1F1 required by the formula Here's my data
genotype X1F1 X2F1
1 R 43.33877 7.881666
2 R 130.34433 65.056984
3 R 53.39783 11.985018
4 R 23.45456 5.683387
5 R 138.50044 61.194956
6 R 108.63964 39.581222
7 R 153.60738 55.854238
8 T 264.96127 108.751380
9 T 222.94124 119.695112
10 T 119.55373 36.793537
11 T 34.97877 12.285921
Upvotes: 2
Views: 206
Reputation: 3414
You can use data.frame
column names in formula. Two lm
below will give the same result:
df <- data.frame(x = 1:100, y = rnorm(100))
# Option 1. As formula
lm(y ~ x, df)
# Option 2. As data.frame index
lm(df[, "y"] ~ df[, "x"])
Upvotes: 1