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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:01:38+00:00 2026-06-12T15:01:38+00:00

I can’t figure out why this isn’t working. I have a data set with

  • 0

I can’t figure out why this isn’t working. I have a data set with 5 columns, n rows. I just want to apply a function to each row and have the result returned in an n by 1 vector.

Just to test out how everything works, i made this simple function:

f1 <- function(uniqueid,Perspvalue,expvalue,stddevi,stddevc) {
    uniqueid+ Perspvalue- expvalue+ stddevi+stddevc
}

and here’s the first few rows of my data set:

> data
     uniqueid   Perspvalue    expvalue      stddevi      stddevc
1           1 2.404421e+03  3337239.00 8.266566e+03 3.324624e+03
2           2 1.345307e+03  3276559.87 7.068823e+03 2.648072e+03
3           3 1.345307e+03  3276559.87 7.068823e+03 2.648072e+03

Note that it’s a data frame (i think), and not a matrix. I loaded in the data from a csv using read.csv.

So i try this: apply(data,1,f1)

But my result is this: Error in uniqueid + Perspvalue : 'Perspvalue' is missing

I expected a number instead of an error.

  • 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-12T15:01:39+00:00Added an answer on June 12, 2026 at 3:01 pm

    You’ll need to use mapply for this, or even more convienient mdply from the plyr package.

    Some example code:

    spam_function = function(a, b) {
      return(a*b)
    }
    
    require(plyr)
    input_args = data.frame(a = runif(1000), b = runif(1000))
    result = mdply(input_args, spam_function)
    > head(result)
               a         b         V1
    1 0.46902575 0.6865863 0.32202668
    2 0.56837805 0.2400993 0.13646717
    3 0.07185661 0.2334754 0.01677675
    4 0.15589191 0.6636891 0.10346377
    5 0.98317092 0.8895609 0.87459042
    6 0.46070479 0.4301685 0.19818071
    

    If you just want the vector of results:

    result_vector = result$V1
    

    Or alternatively, a base R solution using mapply:

    result_mapply = mapply(spam_function, a = input_args$a, b = input_args$b)
    > head(result_mapply)
    [1] 0.2757767 0.1268879 0.5851026 0.7904186
    [5] 0.2186079 0.1091692
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can't figure out how to do this in a pretty way : I have
Can't seem to figure out what's wrong with the simple getJSON call below. It's
Can any one help me in sorting this out in sed/awk/perl Input file Start
Can find why i get this error can someone help? package Android.data; public class
Can you have submenus with the top level set to checkable in WPF? I
Can anyone help me trying to find out why this doesn't work. The brushes
Can I order my users in the database, so I don't have to say
Can I change the field public virtual ClassOne ClassOne { get; set; } to
Can I authenticate with just Google account username and password instead of using OAuth?
Can anyone explain to me why this program: for(float i = -1; i <

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.