Shaun
Shaun

Reputation: 949

Extracting values from a summary output

I run this code and I get following output.

> df$postStrata
[[1]]
[[1]]
  [1] 1 1 2 1 2 1 2 1 2 2 2 1 1 2 1 1 1 1 1 1 2 1 1 1 2 1 1 2 1 1 2 1 2 2 1 1 2 1 2 2 2 1 1 2 2 2 2
 [48] 1 2 1 1 1 1 2 1 1 2 1 1 2 1 2 1 1 1 1 2 2 2 1 1 1 1 2 2 2 2 1 2 1 2 1 2 1 1 1 2 1 1 1 1 2 1 2
 [95] 1 2 2 2 2 1
attr(,"oldweights")
  [1] 0.7894737 0.7894737 1.2790698 0.7894737 1.2790698 0.7894737 1.2790698 0.7894737 1.2790698
 [10] 1.2790698 1.2790698 0.7894737 0.7894737 1.2790698 0.7894737 0.7894737 0.7894737 0.7894737
 [19] 0.7894737 0.7894737 1.2790698 0.7894737 0.7894737 0.7894737 1.2790698 0.7894737 0.7894737
 [28] 1.2790698 0.7894737 0.7894737 1.2790698 0.7894737 1.2790698 1.2790698 0.7894737 0.7894737
 [37] 1.2790698 0.7894737 1.2790698 1.2790698 1.2790698 0.7894737 0.7894737 1.2790698 1.2790698
 [46] 1.2790698 1.2790698 0.7894737 1.2790698 0.7894737 0.7894737 0.7894737 0.7894737 1.2790698
 [55] 0.7894737 0.7894737 1.2790698 0.7894737 0.7894737 1.2790698 0.7894737 1.2790698 0.7894737
 [64] 0.7894737 0.7894737 0.7894737 1.2790698 1.2790698 1.2790698 0.7894737 0.7894737 0.7894737
 [73] 0.7894737 1.2790698 1.2790698 1.2790698 1.2790698 0.7894737 1.2790698 0.7894737 1.2790698
 [82] 0.7894737 1.2790698 0.7894737 0.7894737 0.7894737 1.2790698 0.7894737 0.7894737 0.7894737
 [91] 0.7894737 1.2790698 0.7894737 1.2790698 0.7894737 1.2790698 1.2790698 1.2790698 1.2790698
[100] 0.7894737
attr(,"weights")
  [1] 0.7894737 0.7894737 1.2790698 0.7894737 1.2790698 0.7894737 1.2790698 0.7894737 1.2790698
 [10] 1.2790698 1.2790698 0.7894737 0.7894737 1.2790698 0.7894737 0.7894737 0.7894737 0.7894737
 [19] 0.7894737 0.7894737 1.2790698 0.7894737 0.7894737 0.7894737 1.2790698 0.7894737 0.7894737
 [28] 1.2790698 0.7894737 0.7894737 1.2790698 0.7894737 1.2790698 1.2790698 0.7894737 0.7894737
 [37] 1.2790698 0.7894737 1.2790698 1.2790698 1.2790698 0.7894737 0.7894737 1.2790698 1.2790698
 [46] 1.2790698 1.2790698 0.7894737 1.2790698 0.7894737 0.7894737 0.7894737 0.7894737 1.2790698
 [55] 0.7894737 0.7894737 1.2790698 0.7894737 0.7894737 1.2790698 0.7894737 1.2790698 0.7894737
 [64] 0.7894737 0.7894737 0.7894737 1.2790698 1.2790698 1.2790698 0.7894737 0.7894737 0.7894737
 [73] 0.7894737 1.2790698 1.2790698 1.2790698 1.2790698 0.7894737 1.2790698 0.7894737 1.2790698
 [82] 0.7894737 1.2790698 0.7894737 0.7894737 0.7894737 1.2790698 0.7894737 0.7894737 0.7894737
 [91] 0.7894737 1.2790698 0.7894737 1.2790698 0.7894737 1.2790698 1.2790698 1.2790698 1.2790698
[100] 0.7894737

Is there a way I can extract the attr(,"weights") values. Is there a code to put the values into a list?

Upvotes: 1

Views: 74

Answers (1)

akrun
akrun

Reputation: 887048

We can extract the list element and then use attr

attr(df$postStrata[[1]][[1]], "weights")

If we need to extract from all elements of the list

lapply(df$postStrata, function(x) attr(x[[1]], "weights"))

Upvotes: 1

Related Questions