-1

I have this long list of object (there are 683 rows but I omitted them to make an example):

    >cor

                 statistic     parameter p.value      estimate      null.value alternative method                                
    correlazione 0.9363251     6         0.3852444    0.3570561     0          "two.sided" "Pearson's product-moment correlation"
    correlazione 0.7242781     6         0.4961539    0.2835497     0          "two.sided" "Pearson's product-moment correlation"
    correlazione 4.14294       6         0.006058678  0.8608001     0          "two.sided" "Pearson's product-moment correlation"
    correlazione 0.8672409     6         0.4191373    0.3337491     0          "two.sided" "Pearson's product-moment correlation"
    correlazione -0.7009853    6         0.5095706    -0.2751315    0          "two.sided" "Pearson's product-moment correlation"
    correlazione -0.8861072    6         0.4096661    -0.3401773    0          "two.sided" "Pearson's product-moment correlation"
    correlazione 5.747207      6         0.00120747   0.9199313     0          "two.sided" "Pearson's product-moment correlation"
    correlazione 2.057056      6         0.0854038    0.6430975     0          "two.sided" "Pearson's product-moment correlation"
    correlazione 3.415748      6         0.01421782   0.8126439     0          "two.sided" "Pearson's product-moment correlation"
    correlazione 3.56135       6         0.01190775   0.8239272     0          "two.sided" "Pearson's product-moment correlation"
    correlazione 0.7368482     6         0.4890134    0.2880656     0          "two.sided" "Pearson's product-moment correlation"



    str(cor)

 List of 6147

     $ : Named num 1.46
      ..- attr(*, "names")= chr "t"
     $ : Named num 0.646
      ..- attr(*, "names")= chr "t"
     $ : Named num -0.243
      ..- attr(*, "names")= chr "t"
     $ : Named num 0.195
      ..- attr(*, "names")= chr "t"
      [list output truncated]
     - attr(*, "dim")= int [1:2] 683 9
     - attr(*, "dimnames")=List of 2
      ..$ : chr [1:683] "correlazione" "correlazione" "correlazione" "correlazione" ...
      ..$ : chr [1:9] "statistic" "parameter" "p.value" "estimate" ...

I need the p.value for 683 elements, so I need to create a data frame 683x1. How can I create it?

jonny jeep
  • 383
  • 3
  • 12
  • 1
    why not `df[ , "p.value"]`? – Roman Oct 16 '19 at 19:50
  • 1
    [See here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on making an R question that folks can help with. That includes a sample of data, all necessary code, and a clear explanation of what you're trying to do and what hasn't worked. – camille Oct 16 '19 at 20:21
  • @Jimbou I can't, it reports this message : df[ , "p.value"] Error in df[, "p.value"] : object of type 'closure' is not subsettable – jonny jeep Oct 16 '19 at 20:26

1 Answers1

0

If I understand correctly, cor is a list, and the first element of the list (which is a dataframe) contains the p-values you want to extract?

data.frame(p_val = cor[1]$p.value)
jon
  • 370
  • 1
  • 11
  • I have never seen before this kind of list. You Script reports to me a data frame with 0 columns and 0 rows. I would only to extract from this list the column p values, then I would to convert it into data frame so I can work with it – jonny jeep Oct 16 '19 at 20:28
  • @jonnyjeep try `cor[[1]][ , "p.value"]` or `data.frame(p_val = cor[[1]]$p.value)` – Roman Oct 17 '19 at 07:37