Bob Napkin
Bob Napkin

Reputation: 566

Polynomial root to integer

I've got [1] -5+0i from polyroot(l) function and I don't understand how I can print it like -5. And why row.names=F, col.names=F doesn't work?

l <- c(5, 1)
x <- polyroot(l)
ans <- data.frame(sum(x), prod(x))
print(ans, row.names=F, col.names=F)

Here I need to print -5 -5, but I've got:

 sum.x. prod.x.
  -5+0i   -5+0i

Upvotes: 1

Views: 52

Answers (1)

Lars Lau Raket
Lars Lau Raket

Reputation: 1974

You can remove the name attributes and take out the real part by:

attributes(ans) <- NULL
sapply(ans, Re)

Upvotes: 3

Related Questions