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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:59:07+00:00 2026-06-09T13:59:07+00:00

This is actually a continuation of a previous question: Spline on multiple factors in

  • 0

This is actually a continuation of a previous question:

Spline on multiple factors in data frame

so apologies for going through the first part again. And believe me I tried to solve myself!

So some sample data:

mydf<- data.frame(c("a","a","b","b","c","c"),c("e","e","e","e","e","e")
                 ,as.numeric(c(1,2,3,10,20,30)),
                 as.numeric(c(5,10,20,20,15,10)))

Give some names:

colnames(mydf)<-c("Model", "Class","Seconds", "Speed")

which gives:

> mydf
  Model Class Seconds Speed
1     a     e       1     5
2     a     e       2    10
3     b     e       3    20
4     b     e      10    20
5     c     e      20    15
6     c     e      30    10

Now originally I needed to spline this data and the answer was kindly given as:

library("plyr")
ddply(mydf, .(Model), summarise, Spline = spline(x = Seconds, y = Speed))

which resulted in:

  Model                        Spline
1     a  1.0, 1.2, 1.4, 1.6, 1.8, 2.0
2     a             5, 6, 7, 8, 9, 10
3     b 3.0, 4.4, 5.8, 7.2, 8.6, 10.0
4     b        20, 20, 20, 20, 20, 20
5     c        20, 22, 24, 26, 28, 30
6     c        15, 14, 13, 12, 11, 10

Just as a side note I couldn’t even by hand create this exact structure in R so as to provide an example, even by hand!

So back to the question. I need to change the results so they look something like this:

Model   Seconds Speed
a       1.0     5
a       1.2     6
a       1.4     7
a       1.6     8
a       1.8     9
a       2.0     10
b       3.0     20
b       4.4     20
b       5.8     20
b       7.2     20
b       8.6     20
b       10.0    20
c       20      15
c       22      14
c       24      13
c       26      12
c       28      11
c       30      10

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-09T13:59:08+00:00Added an answer on June 9, 2026 at 1:59 pm

    You mean like this:

    foo <- function(x){ 
        Spline <- spline(x = x$Seconds, y = x$Speed)
        data.frame(Seconds = Spline$x,Speed = Spline$y) 
    }
    out <- ddply(mydf, .(Model),foo )
    

    Now, you might be asking yourself, “How did joran figure that out?” Cuz before I read this question, I hadn’t the foggiest notion what spline returned.

    So my first stop was ?spline, and I skip to the Value section, where I find:

    spline returns a list containing components x and y which give the ordinates where interpolation took place and the interpolated values.

    Ah ha! So for each chunk of the data that ddply ships off to our as yet unwritten function, it needs to take that list of two components and simply convert them into a data frame, so that ddply can easily stitch things back together again.

    Hence I write a function that starts out by simply fitting the spline model:

    Spline <- spline(x = x$Seconds, y = x$Speed)
    

    and then takes the results and packages it into a data frame:

    data.frame(Seconds = Spline$x,Speed = Spline$y) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is actually a three-part question, which I'll explain below, but the questions are:
This is a continuation of my previous question which I posted when I wasn't
Possible Duplicate: Continue Execution Only After .each() Completes This question is actually a continuation
Simple question - what does this actually do? var oq = (ObjectQuery<TEntity>)L2EQuery; return ExecuteFirstorDefault<TEntity>(oq,
This is actually a non-critical question, but I get this warning most of the
This actually stems from on my earlier question where one of the answers made
I don't know if this actually belongs here, maybe this question is more suitable
This actually corresponds to my other question but things get more complicated. I have
This is in continuation of my previous questions (sorry for re-posting similar type of
This question is a continuation of loading long webview over 500kb. So as the

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.