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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:02:13+00:00 2026-05-26T09:02:13+00:00

Looking to learn function writing. I have data laid out in the following (e.g.):

  • 0

Looking to learn function writing. I have data laid out in the following (e.g.):

Genus Species  Wing  Tail
 A       X     10.5  20.3
 A       Y     10.7  20.7
 B       XX    15.2  22.5
 B       XY    15.5  24

I calculate variance for a given trait using the equation:

 sqrt(max(Wing) - min (Wing))

which I sum for all traits.

So I can write the following function so sum variance for the total data set:

variance<- function(data){
t   <- sqrt(max(Tail)-min(Tail))
w   <- sqrt(max(Wing)-min(Wing))
x <- sum(t,w)
x
}

But I can’twork out how to generate a response to give me an output where this result is dependant on the Genus. So i’m looking to generate an output like:

 Genus A    Genus B
  2.345      3.456
  • 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-26T09:02:14+00:00Added an answer on May 26, 2026 at 9:02 am

    I am going to give a new name to your function because it’s just wrong to call it “variance”. I hope you can overlook that. We can work on a dataframe object

    dput(dfrm)
    structure(list(Genus = structure(c(1L, 1L, 2L, 2L), .Label = c("A", 
    "B"), class = "factor"), Species = structure(c(1L, 4L, 2L, 3L
    ), .Label = c("X", "XX", "XY", "Y"), class = "factor"), Wing = c(10.5, 
    10.7, 15.2, 15.5), Tail = c(20.3, 20.7, 22.5, 24)), .Names = c("Genus", 
    "Species", "Wing", "Tail"), class = "data.frame", row.names = c(NA, 
    -4L))
    
    dev2<- function(df){
        t   <- sqrt(max(df[["Tail"]])-min(df[["Tail"]]))
        w   <- sqrt(max(df[["Wing"]])-min(df[["Wing"]]))
        x <- sum(t,w)
       x
       }
    

    Now use it to work on the full dataframe, using the split-lapply strategy, which passes sections of the original dataframe determined by the Genus values to the dev2 function

    lapply( split(dfrm, list(dfrm$Genus)), FUN = dev2)
    $A
    [1] 1.079669
    
    $B
    [1] 1.772467
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been looking at the YouTube Insight function and want to learn how
I'm looking to learn some theory about data/audio/video compression, and would be glad to
Currently looking into learn new technology and silverlight is on the potential list. However,
I'm looking to learn about embedded programming (in C mainly, but I hope to
i'm looking to learn about SSO, and heard about Sun Access Manager and openSSO(?)
I'm looking to learn Windows PowerShell. Can someone give me some really good references
I'm a Java developer looking to learn some C#/ASP.NET. One thing I've never liked
I'm getting started with OpenGL ES on Android and I'd looking to learn some
I'm a web services newbie and I've tried to learn it looking for tutorials
I am looking for recommendations for a starting website to learn how to write

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.