Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to get the line number from the list and write it to a vector

I have a list in which the rows from the data frame are stored.

kl <- list(structure(list(GROUP = "1", col6 = NA_character_, col7 = NA_character_, 
    dif = NA_character_, p.value = NA_character_), row.names = 1L, class = "data.frame"), 
    structure(list(GROUP = "2", col6 = NA_character_, col7 = NA_character_, 
        dif = NA_character_, p.value = NA_character_), row.names = 3L, class = "data.frame"), 
    structure(list(GROUP = "3", col6 = NA_character_, col7 = NA_character_, 
        dif = NA_character_, p.value = NA_character_), row.names = 5L, class = "data.frame"), 
    structure(list(GROUP = "4", col6 = NA_character_, col7 = NA_character_, 
        dif = NA_character_, p.value = NA_character_), row.names = 7L, class = "data.frame"))

how to get the line number from the list and write it to a vector

kl.vec <- c(1,3,5,7)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Test data as below:

kl <- list(structure(list(GROUP = "1",  row.names = 1, class = "data.frame")), 
           structure(list(GROUP = "2",  row.names = 3, class = "data.frame")), 
           structure(list(GROUP = "3",  row.names = 5, class = "data.frame")), 
           structure(list(GROUP = "4",  row.names = 7, class = "data.frame")))

then we can do

sapply(c(1:length(kl)), FUN=function(x) kl[[x]]$row.names)

it returns

1 3 5 7
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading