Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8125737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:54:47+00:00 2026-06-06T06:54:47+00:00

In PHP you can access both the names and values of an array in

  • 0

In PHP you can access both the names and values of an array in a for loop with

foreach ( $array as $key => $value ) {

Is there anything comparable in R, when looping over named lists?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T06:54:49+00:00Added an answer on June 6, 2026 at 6:54 am

    Using some dummy data and a silly contrived example

    ll <- list(A = 1:10, B = LETTERS[1:10], C = letters[1:10])
    

    You can lapply() over the indices of the elements of ll:

    out <- lapply(seq_along(ll),
               function(ind, list, names) {
                   paste(names[ind], "=", paste(list[[ind]], collapse = ", "))
               }, list = ll, names = names(ll))
    
    R> out
    [[1]]
    [1] "A = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10"
    
    [[2]]
    [1] "B = A, B, C, D, E, F, G, H, I, J"
    
    [[3]]
    [1] "C = a, b, c, d, e, f, g, h, i, j"
    

    or for() loop over the list:

    ll2 <- vector("list", length(ll))
    nams <- names(ll)
    for(i in seq_along(ll)) {
        ll2[[i]] <- paste(nams[i], "=", paste(ll[[i]], collapse = ", "))
    }
    ll2
    
    R> ll2
    [[1]]
    [1] "A = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10"
    
    [[2]]
    [1] "B = A, B, C, D, E, F, G, H, I, J"
    
    [[3]]
    [1] "C = a, b, c, d, e, f, g, h, i, j"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In php how can I access an array's values without using square brackets around
In PHP I can use a foreach loop such that I have access to
In config/routes.php <?php return array( 'account/profile/change_password' => 'users/account/change_password', ); I can access site.com/users/account/change_password and
I can access both methods using the twitteroauth php library. Just thinking of how
How can I access a static variable in a separate class in PHP? Is
Currently on my website visitors can directly access different posts by going to www.mywebsite.com/index.php?post=123,
How can i block all access to a php file using mod_sec? The file
I would like to access a MySQL database using PHP. Can someone please explain
I was wondering if PHP can do this as there seems to be no
MySQL connection in PHP can be established in two ways: $mysql = new mysqli('localhost',

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.