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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:56:48+00:00 2026-06-04T23:56:48+00:00

Given the following matrix with weights in ls in the first column and heihts

  • 0

Given the following matrix with weights in ls in the first column and heihts in the second colum:

> wgt.hgt.matrix
     [,1] [,2]
[1,]  180   70
[2,]  156   67
[3,]  128   64
[4,]  118   66
[5,]  202   72

I am looking for a concise way to apply this a binary function like

function(lb, inch) { (lb/inch**2)*703 } -> bmi

to each row of the matrix, resulting in an array, list or vector of with the 5 resulting BMI values. One way I found uses the apply function:

apply(wgt.hgt.matrix, 1, function(row) bmi(row[1], row[2]))

But a splat operator as in Ruby (*) would help making the call more concise and clear:

apply(wgt.hgt.matrix, 1, function(row) bmi(*row))

Does an equivalent to the splat operator exist, i.e. a syntax element telling R to split all vector-like objects to populate argument lists? Are there other, simpler or more concise suggestion for the apply call?

  • 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-04T23:56:50+00:00Added an answer on June 4, 2026 at 11:56 pm

    Using the bmi() function as a vectorized solution is preferable since it has all vectorized operators, as was illustrated in Joshua’s answer. You can also do this with:

    colnames(wgt.hgt.matrix) <- c("lb", "inch")
    with( as.data.frame(wgt.hgt.matrix), bmi(lb,inch) )
    # [1] 25.82449 24.43039 21.96875 19.04362 27.39313
    

    Unfortunately matrices are not good substrate for constructing environments using ‘with’ so coercing to a dataframe was needed above. You could get an apply solution (which will be less time-efficient than a vectorized approach) to work with a version of bmi() re-ritten to take a vector with named elements (as created above):

     bmi <- function(vec) { (vec['lb']/vec['inch']**2)*703 }
     apply(wgt.hgt.matrix, 1, function(row)  bmi(row ) )
    # [1] 25.82449 24.43039 21.96875 19.04362 27.39313
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following Markov Matrix: import numpy, scipy.linalg A = numpy.array([[0.9, 0.1],[0.15, 0.85]]) The
Problem: Given a matrix in which each row and each column is sorted, write
// given following array: $data = array( 0=>array( data=>object1, col=>array( 0=>array( data=>object2, col=>array( 0=>array(
Given following array: var arr = [undefined, undefined, 2, 5, undefined, undefined]; I'd like
Given following Statment: String query = "Select * from T_spareParts where SparePartPK IN (?
Given the following example (using JUnit with Hamcrest matchers): Map<String, Class<? extends Serializable>> expected
Given the following two ways of defining a class method in Ruby: class Foo
Given the following list of presidents do a top ten word count in the
Given the following HTML <b>demo</b> I want to save it to an SQL 2005
Given the following code, is there a way I can call class A's version

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.