1

I am having trouble assigning columns to the strings above them. I believe the proper way to do this is use the attach() function. I have a csv file loaded with columns of data on Flight, O.ring, and Temp. I have tried to clear previously attached data by using the detach() function, but have not had any luck.

### Files saved in the directory below
setwd("/Users/newUser/desktop/programming")
data <- read.table("Challenger.csv", header=TRUE)
attach(data)
O.ring
Error: object 'O.ring' not found
Flight
Error: object 'Flight' not found
Temp
Error: object 'Temp' not found
fit1 <- glm(O.ring ~ Temp + Pressure, family=binomial(logit))
Error in eval(expr, envir, enclos) : object 'O.ring' not found
fit1
Error: object 'fit1' not found

Edit: I also need help accessing the columns stored in data to use them to model. Any idea what the problem is with my fit1?

Rich Scriven
  • 97,041
  • 11
  • 181
  • 245
stacker1919
  • 13
  • 1
  • 4
  • With this, how to I use the columns to model my data? It looks like the only way to access it is like this: str(Flight.Temp.Pressure.O.ring.Number) – stacker1919 Mar 30 '17 at 23:47
  • It doesn't look like you read your data in correctly. How is your file structured? read.table assumes it's white space delimited but that does not seem to be the case. – MrFlick Mar 31 '17 at 02:39

1 Answers1

9

Don't use attach(). Ever. Forget it exists.

glm() has a data argument. Using that proves much less stressful.

glm(O.ring ~ Temp + Pressure, family = binomial(logit), data = data)

If you want to know why attach() is not advisable, see Why is it not advisable to use attach() in R and what should I use instead?

Community
  • 1
  • 1
Rich Scriven
  • 97,041
  • 11
  • 181
  • 245
  • Using `attach()` resulted in extra categories being added to my boxplot, which were not present in the data. At first I didn't know the cause. Thanks for this advice. – Finger Picking Good Oct 29 '19 at 00:05