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 8314203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:44:24+00:00 2026-06-08T20:44:24+00:00

I have a list NList of numeric vector like [[1]] [1] 1959 9 4

  • 0

I have a list NList of numeric vector like

[[1]]
[1] 1959 9 4 62

[[2]]
[1] 2280  2  13

[[3]]
[1] 15 4  13

[[4]]
[1] 2902  178   13

and the structure is like

list(c(1959, 13), c(2280, 178, 13), c(2612, 178, 13), c(2902, 
178, 13), c(2389, 178, 13), c(216, 736, 13), c(2337, 178, 13), 
    c(2639, 2126, 13), c(2924, 676, 178, 13), c(2416, 674, 178, 
    13), c(2223, 13), c(842, 178, 13), c(2618, 1570, 178, 13), 
    c(854, 178, 13), c(1847, 178, 13), c(2529, 178, 13), c(511, 
    178, 13), c(2221, 736, 13), c(415, 674, 178, 13), c(2438, 
    178, 13), c(2127, 178, 13), c(1910, 2126, 13), c(1904, 674, 
    178, 13), c(2310, 674, 178, 13), c(1732, 178, 13), c(1843, 
    178, 13), c(2539, 178, 13), c(1572, 676, 178, 13), c(1616, 
    876, 13).....)

I want to iterate the numeric vectors in this list, I would like to do something as:

  sum<- 0
  index<-1
  list1 <- apply(NList,1,function (i){
  #I want to get each of the numeric vector here
  row <- NList[i]

  #then I want to iterate the numeric vector for some calculation.
  #I am expecting, for [[1]], I get f(1959,9)+f(9,4)+f(4,62), in which f is my customized function, below I use a simple multiple as example
  for (j in (1:(length(row)-1)))
  {
    origin <- row[j]
    dest <- row[j+1]
    #a simple calculation example...I am expecting an array of sum which is the calculation result 
    sum[index] <- sum[index] + origin*dest
  }
  index <- index+1  

  })

but it does not work and returns:

dim(X) must have a positive length

The lapply is not working for me and return sum as 0…

listR1 <- lapply(NList,function (i){
  row <- i
  for (j in 1:length(row))
  {origin <- row[j]
  dest <- row[j+1]
  sum[index] <- sum[index] + origin*dest
  }

  })

Did I miss something? How can I do this?
Thanks!

  • 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-08T20:44:27+00:00Added an answer on June 8, 2026 at 8:44 pm

    I took the function out of your apply statement to look at it a bit closer.

        f=function(Row) 
        {
         Sum<- 0
          for (j in 1:(length(Row)-1)  )
          {
                Sum<- j + Row[j]*Row[j+1]
          }
         Sum    # returns the Sum
        }
    

    Then I can apply the function to each row with:

      list1 <- lapply(NList,f)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have list of input area in the form with id like contact1_title, contact2_title,
I have list of structure. I want to modify a particular data from the
I have a list (i.e. Dim nList as new List(of className) ). Each class
i have list like that: <ul> <li><a...>...</a></li> <li>...</li> </ul> where both type of listelements
I have a code like this: <s:select id=s list=list listKey=id listValue=displayValue> When I get
I have a nested list e.g.: nlist = [ [1, 2, 3], [4, 5,
I have list of links, like: <div class=links> <a href=# class=link1>link 1</a> <a href=#
I have list of dictionaries like this: [{'X': '10'}, {'time': '08:34:51', 'load': 28.27, 'memory':
I have the following problem: list.c struct nmlist_element_s { void *data; struct nmlist_element_s *next;
I have list of articles on the page in table and i want to

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.