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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:43:13+00:00 2026-05-20T20:43:13+00:00

I am trying create a data.frame from which to create a graph. I have

  • 0

I am trying create a data.frame from which to create a graph. I have a function and two vectors that I want to use as the two inputs. This is a bit simplified, but basically all I have is:

relGPA <- seq(-1.5,1.5,.2)
avgGPA <- c(-2,0,2)

f <- function(relGPA, avgGPA) 1/(1+exp(sum(relGPA*pred.model$coef[1],avgGPA*pred.model$coef[2])))

and all I want is a data.frame with 3 columns for the avgGPA values, and 16 rows for the relGPA values with the resulting values in the cells.

I apologize for how basic this is, but I assure you I have tried to make this happen without your assistance. I have tried following the examples on the sapply and mapply man pages, but I’m just a little too new to R to see what I’m trying to do.

Thanks!

  • 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-05-20T20:43:13+00:00Added an answer on May 20, 2026 at 8:43 pm

    Cannot be tested with the information offered, but this should work:

    expGPA  <- outer(relGPA, avgGPA, FUN=f) # See below for way to make this "work"
    

    Another useful function when you want to generate combinations is expand.grid and this would get you the “long form”:

    expGPA2 <-expand.grid(relGPA, avgGPA)
    expGPA2$fn <- apply(expGPA2, 1, f)
    

    The long form is what lattice and ggplot will expect as input format for higher level plotting.

    EDIT: It may be necessary to construct a more specific method for passing column references to the function as pointed out by djhurio and (solved) by Sam Swift with the Vectorize strategy. In the case of apply, the sum function would work out of the box as described above, but the division operator would not, so here is a further example that can be generalized to more complex functions with multiple arguments. All the programmer needs is the number of the column for the appropriate argument in the “apply()”-ed” function, because (unfortunately) the column names are not carried through to the x argument:

    > expGPA2$fn <- apply(expGPA2, 1, function(x) x[1]/x[2])
    > str(expGPA2)
    'data.frame':   48 obs. of  3 variables:
     $ Var1: num  -1.5 -1.3 -1.1 -0.9 -0.7 ...
     $ Var2: num  -2 -2 -2 -2 -2 -2 -2 -2 -2 -2 ...
     $ fn  : num  0.75 0.65 0.55 0.45 0.35 ...
     - attr(*, "out.attrs")=List of 2
      ..$ dim     : int  16 3
      ..$ dimnames:List of 2
      .. ..$ Var1: chr  "Var1=-1.5" "Var1=-1.3" "Var1=-1.1" "Var1=-0.9" ...
      .. ..$ Var2: chr  "Var2=-2" "Var2= 0" "Var2= 2"
    

    Edit2: (2013-01-05) Looking at this a year later, I realized that SamSwift’s function could be vectorized by making its body use “+” instead of sum:

     1/(1+exp( relGPA*pred.model$coef[1] + avgGPA*pred.model$coef[2]) # all vectorized fns
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create an XML file based on data fields from a
I'm trying to create a TCP connection and send/read data that uses SSL, but
I'm currently trying to create a kernel module that will produce data based on
I am trying to create a simple page that enters data in to a
I am trying to create a data access layer using t4 and C#. I
Trying to create a list to return some JSON data to a view. Following
I am trying to create a website where I host my data on google
I am trying create a WCF service that leverages the WPF MediaPlayer on the
I'm trying to work on data from .csv files of known general format but
From a user form: I am trying to insert the following data: 1) First

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.