using lm function for imported excel data

Hi again,
I have tried to do multiple regression after learning it theoretically for my dataset.

fit<-lm(Age ~ source for cook, data=ckd)
but the response is
Error: unexpected 'for' in "fit<-lm(Age ~ source for"

what have gone wrong. This is an imported dataset from excel

structure(list(Age = c(53, 68, 38, 35, 39, 60, 48, 60, 40, 65, 
35, 38, 39, 42, 50, 18, 54, 53, 67, 37, 60, 30, 24, 67, 40, 22, 
53, 73, 37, 42, 38, 16, 44, 40, 46, 42, 41, 48, 41, 40, 67, 37, 
44, 47, 36, 39, 38, 41, 18, 52, 36, 26, 39, 33, 43, 40, 52, 67, 
37, 60, 30, 24, 67, 40, 22, 53, 73, 37, 42, 38), SEx = c("m", 
"m", "m", "m", "m", "m", "f", "f", "m", "m", "m", "m", "m", "m", 
"m", "m", "m", "f", "f", "m", "m", "m", "f", "m", "m", "m", "m", 
"m", "m", "m", "f", "f", "m", "m", "f", "m", "f", "m", "f", "m", 
"f", "m", "m", "m", "f", "f", "f", "m", "f", "f", "f", "f", "m", 
"f", "f", "f", "m", "f", "m", "m", "m", "f", "m", "m", "m", "m", 
"m", "m", "m", "f"), Occupation = c("farmer", "farmer", "farmer", 
"business", "farmer", "farmer", "farmer", "farmer", "farmer", 
"no", "teacher", "teacher", "teacher", "teacher", "PHI", "farmer", 
"post", "farrmer", "farrmer", "bass", "farmer", "gramaniladhari", 
"hw", "farrmer", "farrmer", "labour", "farmer", "farmer", "barber", 
"farmer", "hw", "student", "retired", "farmer", "hw", "clerk", 
"hw", "farmer", "hw", "farmer", "farmer", "driver", "army", "farmer", 
"hw", "hw", "hw", "farmer", "student", "farmer", "farmer", "hw", 
"farmer", "hw", "hw", "hw", "teacher", "farrmer", "bass", "farmer", 
"gramaniladhari", "hw", "farrmer", "farrmer", "labour", "farmer", 
"farmer", "barber", "farmer", "hw"), No = c(4, 3, 7, 3, 4, 2, 
2, 5, 4, 2, 4, 5, 4, 4, 4, 5, 4, 2, 3, 4, 5, 5, 5, 2, 3, 3, 5, 
4, 4, 5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, 1, 2, 2, 2, 2, 2), `seen filter` = c(1, 2, 1, 
1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, NA, 
1, 1, 1, 1, 1, 1, 1, NA, 1, NA, 2, 1, 2, 2, NA, NA, 2, NA, 1, 
NA, NA, 2, 2, 2, NA, NA, 2, 2, 2, NA, NA, 2, 2, 1, 1, 1, 1, 1, 
NA, 1, 1, 1, 1, 1, 1, 1), `duration of filter` = c(0, 0, 0, 0, 
0, 0, 0, 0, 0, 0.5, 0, 3, 1.5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0.5, 
NA, 0, 0.5, 0, 0, 0, 0, 0, NA, 0, NA, 0, 1, 0, 0, NA, NA, 0, 
NA, 4, NA, NA, 0, 0, 0, NA, NA, 0, 0, 0, NA, NA, 0, 0, 0, 0, 
0, 0, 0.5, NA, 0, 0.5, 0, 0, 0, 0, 0), `qualitym of filter` = c(2, 
2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 
2, NA, 2, 2, 2, 2, 2, 2, 2, NA, 2, NA, 2, 1, 2, 2, NA, NA, 2, 
NA, 1, NA, NA, 2, 2, 2, NA, NA, 2, 2, 2, NA, NA, 2, 2, 2, 2, 
2, 1, 2, NA, 2, 2, 2, 2, 2, 2, 2), `method of q a` = c("0", "0", 
"0", "0", "certificate", "0", "0", "0", "0", "0", "0", "0", "0", 
"0", "0", "0", "0", "0", "0", "0", "0", "shown", "0", NA, "0", 
"0", "0", "0", "0", "0", "0", NA, "0", NA, "0", "certificate", 
"0", "0", NA, NA, "0", NA, "shown", NA, NA, "0", "0", "0", NA, 
NA, "0", "0", "0", NA, NA, "0", "0", "0", "0", "0", "shown", 
"0", NA, "0", "0", "0", "0", "0", "0", "0"), `water source job` = c(6, 
6, 6, 6, 6, 6, 6, 6, 6, NA, 6, 6, 6, 6, 2, 4, 6, 6, 6, 6, 6, 
2, 6, 2, 6, 6, 6, 6, 6, 6, NA, 2, 6, NA, NA, 2, NA, 6, NA, 2, 
6, NA, 2, 2, NA, NA, NA, 6, 2, 2, 6, NA, 6, NA, NA, NA, 6, 6, 
6, 6, 2, 6, 2, 6, 6, 6, 6, 6, 6, NA), `job filter source` = c(1, 
2, 2, 2, 1, 2, 2, 2, 2, NA, 1, 1, 1, 1, 1, NA, 2, 2, 2, 2, 2, 
NA, 2, NA, 2, 2, 2, 2, 2, 2, NA, NA, 2, 2, NA, NA, NA, 2, NA, 
NA, 2, 2, NA, NA, NA, NA, NA, 2, NA, NA, 2, NA, 2, NA, NA, NA, 
2, 2, 2, 2, NA, 2, NA, 2, 2, 2, 2, 2, 2, NA), `job filter seen` = c(1, 
2, 1, 1, 1, 2, 2, 2, 2, NA, 1, 1, 1, 1, 1, NA, 2, 1, 1, 2, 1, 
NA, 1, NA, 1, 1, 1, 1, 1, 1, NA, NA, 2, NA, NA, NA, NA, 2, NA, 
NA, 2, NA, NA, NA, NA, NA, NA, 2, NA, NA, 2, NA, 2, NA, NA, NA, 
2, 1, 2, 1, NA, 1, NA, 1, 1, 1, 1, 1, 1, NA), `job filetr duration` = c(0, 
0, 0, 0, 0, 0, 0, 0, 0, NA, 0, 2, 0, 1, 0, NA, 0, 0, 0, 0, 0, 
NA, 0.5, NA, 0, 0.5, 0, 0, 0, 0, NA, NA, 0, NA, NA, NA, NA, 0, 
NA, NA, 0, NA, NA, NA, NA, NA, NA, 0, NA, NA, 0, NA, 0, NA, NA, 
NA, 0, 0, 0, 0, NA, 0.5, NA, 0, 0.5, 0, 0, 0, 0, NA), `job filter q a` = c(2, 
2, 2, 2, 2, 2, 2, 2, 2, NA, 2, 2, 2, 2, 2, NA, 2, 2, 2, 2, 2, 
NA, 2, NA, 2, 2, 2, 2, 2, 2, NA, NA, 2, NA, NA, NA, NA, 2, NA, 
NA, 2, NA, NA, NA, NA, NA, NA, 2, NA, NA, 2, NA, 2, NA, NA, NA, 
2, 2, 2, 2, NA, 2, NA, 2, 2, 2, 2, 2, 2, NA), `method job filketr qa` = c(0, 
0, 0, 0, 0, 1, 0, 0, 0, NA, 0, 0, 0, 0, 0, NA, 0, 0, 0, 0, 0, 
NA, 0, NA, 1, 3, 0, 0, 0, 0, NA, NA, 0, NA, NA, NA, NA, 0, NA, 
NA, 0, NA, NA, NA, NA, NA, NA, 0, NA, NA, 0, NA, 0, NA, NA, NA, 
0, 0, 0, 0, NA, 0, NA, 1, 3, 0, 0, 0, 0, NA), `water puirity home` = c(3, 
4, 4, 4, 3, 1, 4, 4, 4, 3, 3, 3, 1, 3, 2, 3, 3, 2, 3, 3, 3, 1, 
3, 4, 3, 4, 3, 3, 3, 4, 3, 1, 4, 4, 1, 1, 3, 4, 4, 1, 3, 1, 4, 
4, 1, 1, 1, 1, 2, 4, 4, 1, 1, 1, 1, 4, 2, 3, 3, 3, 1, 3, 4, 3, 
4, 3, 3, 3, 4, 3), `j-ob  water purity` = c(NA, 4, 4, 4, 3, 2, 
4, 4, 4, NA, 3, 3, 3, 3, 2, 3, 3, 4, 4, 3, 3, 2, NA, 4, 2, 2, 
3, 2, 3, 4, NA, 4, 4, 4, NA, 4, NA, 4, NA, 4, 3, 1, 4, 4, NA, 
NA, NA, 2, 4, 4, 4, NA, 4, NA, NA, NA, 2, 4, 3, 3, 2, NA, 4, 
2, 2, 3, 2, 3, 4, NA), `filter home` = c(0, 2, 1, 2, 1, NA, 2, 
2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, NA, NA, 2, 
NA, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 
2, 1, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, NA, NA, 2, NA, 
2, 2, 2), `type of filter home` = c(0, 2, 2, NA, 2, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, 2, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 2, NA, NA, NA, 
2, NA, NA, NA, NA, NA, NA, NA, 2, NA, NA, NA, NA, NA, NA, NA, 
2, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), `duration of home filter` = c(0, 
NA, 5, NA, 3, NA, NA, NA, NA, NA, NA, NA, NA, NA, 3, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, 5, NA, NA, NA, 3, NA, NA, NA, NA, NA, NA, NA, 5, 
NA, NA, NA, NA, NA, NA, NA, 8, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA), `q a filter home` = c("0", "0", "0", NA, 
"0", NA, NA, NA, NA, NA, NA, NA, NA, NA, "change", NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, "0", NA, NA, NA, "0", NA, NA, NA, NA, NA, NA, NA, "0", 
NA, NA, NA, NA, NA, NA, NA, "0", NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA), `filter job` = c(2, 2, 1, 2, 1, 2, 2, 
2, 2, NA, 1, 2, 1, 2, 1, 2, 2, 2, 2, 2, 2, 2, NA, 2, 2, 2, 2, 
2, 2, 2, NA, 2, 2, 2, NA, 2, NA, 2, 1, 2, 2, NA, 2, 2, NA, NA, 
NA, NA, 2, 2, 2, NA, 2, NA, NA, NA, 2, 2, 2, 2, 2, NA, 2, 2, 
2, 2, 2, 2, 2, NA), `type of filter job` = c(NA, NA, 2, NA, 2, 
NA, NA, NA, NA, NA, 1, NA, 1, NA, 2, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, 1, NA, NA, 2, NA, NA, NA, NA, NA, 1, NA, NA, NA, NA, NA, 
NA, NA, NA, 3, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA), `duration filter job` = c(NA, NA, 5, NA, 0, NA, NA, NA, 
NA, NA, 2, NA, 1.5, NA, 1, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 3, NA, 
NA, NA, NA, NA, NA, NA, NA, 2, NA, NA, NA, NA, NA, NA, NA, NA, 
0, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), `q a filter job` = c(NA, 
NA, "0", NA, "0", NA, NA, NA, NA, NA, "0", NA, "personqa", NA, 
"0", NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, "1", NA, NA, NA, NA, NA, 
NA, NA, NA, "0", NA, NA, NA, NA, NA, NA, NA, NA, "0", NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), `source for cook` = c(2, 
6, 6, 6, 6, 6, 2, 2, 6, 6, 2, 6, 2, 6, 2, 6, 6, 1, 6, 6, 6, 2, 
6, 2, 2, 1, 2, 6, 2, 2, 2, 2, 6, 2, 2, 2, 2, 6, 6, 2, 6, 2, 2, 
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 6, 6, 6, 6, 2, 6, 2, 2, 
1, 2, 6, 2, 2, 2), `purity for cook` = c(4, 4, 3, 4, 3, 1, 4, 
4, 4, 3, 4, 3, 4, 3, 4, 3, 3, 4, 4, 3, 4, 4, 3, 4, 4, 4, 4, 3, 
4, 4, 4, 4, 3, 1, 1, 4, 2, 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 4, 4, 3, 4, 4, 4, 4, 3, 4, 4, 4
), screened = c(3, 2, 1, 3, 2, 2, 0, 1, 3, 0, 3, 5, 2, 2, 1, 
2, 2, 2, 3, 2, 3, 3, 1, 1, 2, 3, 1, 4, 3, 2, 2, 2, 2,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, 0, 
1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0), `CKD is` = c(3, 
3, 3, 1, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 3, 3, 3, 3, 1, 
1, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 3, 1, 
3, 3, 3, 3, 3, 1, 3, 3, 3, 3, 1, 3, 2, 3, 3, 3, 3, 1, 1, 3, 3, 
3, 3, 3, 1, 1, 1), `tp prevent ckd drinkin` = c(3, 1, 1, 2, 3, 
4, 3, 3, 3, 1, 1, 1, 3, 3, 3, 4, 2, 1, 4, 4, 4, 1, 3, 4, 1, 3, 
4, 4, 4, 1, 3, 3, 3, 4, 1, 2, 1, 3, 2, 2, 3, 4, 3, 4, 4, 4, 4, 
4, 1, 4, 4, 4, 4, 3, 4, 3, 4, 4, 4, 4, 1, 3, 4, 1, 3, 4, 4, 4, 
1, 3), `to prevent cook` = c(4, 1, 1, 3, 3, 4, 1, 1, 3, 1, 1, 
1, 3, 3, 3, 4, 1, 4, 4, 4, 4, 1, 1, 4, 4, 1, 4, 4, 4, 1, 3, 1, 
3, 4, 3, 2, 1, 3, 2, 4, 3, 4, 1, 4, 4, 4, 4, 4, 1, 4, 4, 4, 4, 
4, 4, 3, 4, 4, 4, 4, 1, 1, 4, 4, 1, 4, 4, 4, 1, 3)), row.names = c(NA, 
-70L), class = c("tbl_df", "tbl", "data.frame"))
fit <- lm(Age ~ source + for + cook, data = chk)

If for and cook are variables

can you please give me an exmple. Let us say I have a variable called "water for cooking"

Like this:

`water for cooking`

The backtick is on the top left of the keyboard, above 'tab' and different to the apostrophe.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

Your column/variable names should not have spaces in them. If they do, you need to use ``backticks around them.

1 Like