Aystealthy
Aystealthy

Reputation: 169

How to reference only the number in linear regression function

in r let's say I have this: house_model is the linear regression model

b_0 = house_model$coefficients[1]
b_1 = house_model$coefficients[2]

print(b_0)

print(b_1)

and this will output

(Intercept) 
-1.171116 
area
0.17545795

So I want to only get the numbers and not the names. I want to only see -1.171116 and .17545795. is there a way to do this?

Upvotes: 0

Views: 68

Answers (2)

tstudio
tstudio

Reputation: 307

You can use the as.numeric function as follows:

# without an additional variable
print(as.numeric(house_model$coefficients[1]))

# with an additional variable
print(as.numeric(b_0))

Upvotes: 0

Ben Bolker
Ben Bolker

Reputation: 226087

print(unname(b0))

or

cat(b0,"\n")

(the "\n" is to add a newline character; cat() also skips the [1] at the beginning of the line)

Upvotes: 1

Related Questions