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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:29:42+00:00 2026-06-08T21:29:42+00:00

Test data and method for determining it is located at: Use of IF function

  • 0

Test data and method for determining it is located at: Use of IF function in R

I need to enter the ‘Test’ data into another function. The data for x and y is provided below (essentially two options, 1 = (89.3, 12.1) and 2 = (97.2, 8.5). The equation below is part of much larger function but this is where the problem is. What i want to do is to call each of the values indiviudally from the vector we have (Test) and for the output to be have 2 values for each value in test. When i link Test in directly i receive a new vector with 50 output values which makes no real sense. If i put the first value from the Test vector in, i receive an output of 2 values which is correct (i have checked this manually).

set.seed(1)
Test <- ifelse(runif(50, 0, 1) < 0.69, rnorm(50, 25, 4), rnorm(50, 28, 4.3))


x <- c(89.3, 97.2)
y <- c(12.1, 8.5)

c(-0.75*(((Test)-x)/y)^2)

output is currently this from the above function:

 [1] -21.32750 -55.05068 -25.23216 -49.25087 -20.09236 -53.28421 -19.61593
 [8] -51.81307 -21.32136 -62.68412 -22.28700 -56.50245 -21.33593 -47.71792
[15] -18.53459 -55.10348 -16.12545 -42.79888 -19.73790 -40.38937 -17.77048
[22] -51.94862 -19.20262 -54.78823 -18.92120 -51.75187 -22.82277 -52.08655
[29] -18.82475 -45.86141 -16.28231 -56.33673 -24.02006 -50.75048 -14.97440
[36] -40.67076 -20.51602 -50.05597 -21.04648 -58.66084 -20.32455 -65.47588
[43] -20.01028 -53.19754 -15.84125 -52.88386 -23.09141 -50.51265 -19.73710
[50] -50.32994

but taking the first value from test and putting it in manually gives this:

c(-0.75*(((24.77549)-x)/y)^2)
[1] -21.32750 -54.44958

which is what i want for all 50 values in test

Thanks for any help.

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

    Use sapply:

    set.seed(1)
    Test <- ifelse(runif(50, 0, 1) < 0.69, rnorm(50, 25, 4), rnorm(50, 28, 4.3))
    
    x <- c(89.3, 97.2)
    y <- c(12.1, 8.5)
    
    result = sapply(Test, function(t) c(-0.75*(((t)-x)/y)^2))
    

    result is then a 2×50 matrix:

    > result
              [,1]      [,2]      [,3]      [,4]      [,5]      [,6]      [,7]
    [1,] -21.32750 -21.59186 -25.23216 -19.04891 -20.09236 -20.81548 -19.61593
    [2,] -54.44959 -55.05068 -63.29020 -49.25087 -51.63562 -53.28421 -50.54767
              [,8]      [,9]     [,10]     [,11]     [,12]     [,13]     [,14]
    [1,] -20.17012 -21.32136 -24.96341 -22.28700 -22.23106 -21.33593 -18.37988
    [2,] -51.81307 -54.43561 -62.68412 -56.62937 -56.50245 -54.46874 -47.71792
             [,15]     [,16]     [,17]     [,18]     [,19]     [,20]     [,21]
    [1,] -18.53459 -21.61509 -16.12545 -16.24298 -19.73790 -15.20235 -17.77048
    [2,] -48.07270 -55.10348 -42.52723 -42.79888 -50.82633 -40.38937 -46.31876
             [,22]     [,23]     [,24]     [,25]     [,26]     [,27]     [,28]
    [1,] -20.22954 -19.20262 -21.47642 -18.92120 -20.14330 -22.82277 -20.29001
    [2,] -51.94862 -49.60262 -54.78823 -48.95848 -51.75187 -57.84436 -52.08655
             [,29]     [,30]     [,31]     [,32]     [,33]     [,34]     [,35]
    [1,] -18.82475 -17.57154 -16.28231 -22.15805 -24.02006 -19.70470 -14.97440
    [2,] -48.73760 -45.86141 -42.88975 -56.33673 -60.55407 -50.75048 -39.86019
             [,36]     [,37]     [,38]     [,39]     [,40]     [,41]     [,42]
    [1,] -15.32366 -20.51602 -19.40083 -21.04648 -23.18320 -20.32455 -26.20255
    [2,] -40.67076 -52.60188 -50.05597 -53.81015 -58.66084 -52.16534 -65.47588
             [,43]     [,44]     [,45]     [,46]     [,47]     [,48]    [,49]
    [1,] -20.01028 -20.77743 -15.84125 -20.63975 -23.09141 -19.60061 -19.7371
    [2,] -51.44830 -53.19754 -41.86986 -52.88386 -58.45297 -50.51265 -50.8245
             [,50]
    [1,] -19.52067
    [2,] -50.32994
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My flash code: var request=new URLRequest('http://localhost/test.php'); request.method = URLRequestMethod.POST; var data = new URLVariables();
We have a method which initialises a test database as follows: $db=file_get_contents('test-data.sql'); /* @var
Frequently we need to get some test data from our production sql server 2008
This is my GET Method to get my data from my DataTable Private Function
I'm working on a feature request for a .NET test data builder. I need
Is there any test-data generation framework out there, specially for Python? To make it
I'm creating test data for a Rails app. How do I define the value
I want to populate my database with test data my user and profile models
I am trying to plot some test data (show at the end of this
Is there any tool to generate test data based on specific requirements? e.g. Size,

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.