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

  • Home
  • SEARCH
  • 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 8061867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:29:02+00:00 2026-06-05T10:29:02+00:00

Right now I have two data frames in R, contains some data that looks

  • 0

Right now I have two data frames in R, contains some data that looks like this:

> data
  p a         i
1 1 1 2.2561469
2 5 2 0.2316390
3 2 3 0.4867456
4 3 1 0.1511705
5 4 2 0.8838884

And one the contains coefficients that looks like this:

> coef
         3        2        1
1 29420.50 31029.75 29941.96
2 26915.00 27881.00 27050.00
3 27756.00 28904.00 28699.40
4 28345.33 29802.33 28377.56
5 28217.00 29409.00 28738.67

These data frames are connected as each value in data$a corresponds to a column name in coef and data$p corresponds to row names in coef.

I need to apply these coefficients to multiply these coefficients by the values in data$i by matching the row and column names in coef to data$a and data$p.

In other words, for each row in data, I need to use data$a and data$p for each row to pull a specific number from coef that will be multiplied by the value of data$i for that row to create a new vector in data that looks something like this:

> data
  p a         i          z
1 1 1 2.2561469      67553
2 5 2 0.2316390       6812
3 2 3 0.4867456         .
4 3 1 0.1511705         .
5 4 2 0.8838884         .

I was thinking I should create factors in my coef data frame based on the row and column names but am unsure of where to go from there.

Thanks in advance,

Ian

  • 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-05T10:29:03+00:00Added an answer on June 5, 2026 at 10:29 am

    If you order your coef data.frame, you can just index them as though the column names weren’t there.

    coef <- coef[,order(names(coef))]
    

    Then apply a function to each row:

    myfun <- function(x) {
      x[3]*coef[x[1], x[2]]
    }
    
    data$z <- apply(data, 1, myfun)
    
    > data
      p a         i         z
    1 1 1 2.2561469 67553.460
    2 5 2 0.2316390  6812.271
    3 2 3 0.4867456 13100.758
    4 3 1 0.1511705  4338.503
    5 4 2 0.8838884 26341.934
    > 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now I have these buttons that line up nicely, but they have some
So, I have a page that looks like the following: alt text http://img704.imageshack.us/img704/5973/croppercapture3.png This
Right now users have to two ways to send data to my application: upload
I have a text box that contains lines of data similar to this: sheep
I actually have right now two questions: 1) What font faces are preferred for
Right now I have some functionality working but its really ugly and I know
Right now I have this layout: <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical android:layout_width=fill_parent android:layout_height=fill_parent
Right now I have a tableview, and I can assure you that the delegate
Right now I have this jQuery('.widget-prop').keyup(function() { var prop = jQuery(this).attr('id'); var val =
This is probably a simple one... Right now I have a working web service

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.