1

This is a very quick and simple question that I am sure has been asked repreatedly on here. However after 45 minutes of searching I cannot answer the problem. Please link to whichever is the relevant question or delete it if needed.

I have the following:

>str(slope)
List of 55
$ : Named num [1:2] -0.00044 0.00311
..- attr(*, "names")= chr [1:2] "(Intercept)" "y"
$ : Named num [1:2] 1.374 -0.0276
..- attr(*, "names")= chr [1:2] "(Intercept)" "y"
$ : Named num [1:2] 3.704 -0.102
..- attr(*, "names")= chr [1:2] "(Intercept)" "y"
$ : Named num [1:2] 9.275 -0.294
..- attr(*, "names")= chr [1:2] "(Intercept)" "y"
$ : Named num [1:2] 15.76 -0.46
..- attr(*, "names")= chr [1:2] "(Intercept)" "y"
$ : Named num [1:2] 16.27 -0.443
..- attr(*, "names")= chr [1:2] "(Intercept)" "y"
$ : Named num [1:2] 25.973 -0.717

How do access all values of "y" e.g. if I want to plot them? I can access individual "y" values using:

> slope[[ c(1, 2) ]]
[1] 0.003111922

but not all of them at once.

user1912925
  • 781
  • 1
  • 11
  • 25

2 Answers2

1

Try using sapply and [[:

sapply(slope, '[[', "y")

or maybe

sapply(slope, '[[', 2)

If it doesn't work, then provide a reproducible example and some data.

Community
  • 1
  • 1
Jilber Urbina
  • 58,147
  • 10
  • 114
  • 138
1
sapply(slope, `[`, 2)

Also try

foo <- do.call(rbind, slope)
foo[,2]
Aaron left Stack Overflow
  • 36,704
  • 7
  • 77
  • 142