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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:44:44+00:00 2026-06-10T21:44:44+00:00

I am working in R and I am wanting to iterate through the rows

  • 0

I am working in R and I am wanting to iterate through the rows of a list and to reference the column value by name like this:

for(row in Data) {
    name <- row$name
    age <- row$age
    #do something cool here
}

Where my data looks like this:

name, age, gender, weight
Bill, 23, m, 134
Carl, 40, m, 178

I know that this should be trivial but I can not find help on it. Thanks ahead of time.

So here is the raw data I am working with. The earlier table was an example:

structure(list(startingTemp = c(100L, 100L, 100L, 100L, 100L), 
    endingTemp = c(1L, 1L, 1L, 1L, 1L), movesPerStep = c(200000L, 
    100000L, 20000L, 10000L, 2000L), coolingCoefficient = c(0.99, 
    0.99, 0.99, 0.99, 0.99), numberTempSteps = c(459L, 459L, 
    459L, 459L, 459L), costPerRun = c(91800000L, 45900000L, 9180000L, 
    4590000L, 918000L)), .Names = c("startingTemp", "endingTemp", 
"movesPerStep", "coolingCoefficient", "numberTempSteps", "costPerRun"
), row.names = c(NA, 5L), class = "data.frame")
  • 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-10T21:44:45+00:00Added an answer on June 10, 2026 at 9:44 pm

    You can do this using apply:

    apply(Data, 1, function(row) {
        name <- row["name"]
        age <- row["age"]
        #do something cool here
    })
    

    This is usually used to return a new vector, matrix or list, which depends on what the function returns. For example, let’s say you want to apply the function numberTempSteps / costPerRun to each row. You would do:

    apply(Data, 1, function(row) row["numberTempSteps"] / row["costPerRun"])
    

    (Note that for this example, you could also just do Data$numberTempSteps / Data$costPerRun).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working with H2 I get this error when I try to write a row
I am working on a simple to do list application, and I am wanting
I am working in java and wanting to use something like output parameters. Here
I'm working on a function that iterates through a list of ports and calls
**I currently have this jQuery drop menu working fine but I'm wanting the parent
I've got this little calculator I'm working on - http://jsfiddle.net/sturobson/reCjA/31/ I'm currently wanting it
Busy working on Visual Studio 2010 Express for Windows phone and is wanting to
I'm wanting to get a WCF-over-TCP service working. I was having some problems with
I've been working on my first Metro application and I'm wanting to change my
I am wanting to update a css attribute using jQuery but it isnt working.

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.