Writing Your Own Functions in R: Introduction

Поделиться
HTML-код
  • Опубликовано: 25 июл 2024
  • First in a series of videos about how to write and use your own functions in R. The full series is available as a play list: • Writing Your Own Funct...
    This material is part of the Functions Lesson in the Data Carpentry for Biologists course. Check out the lesson for exercises to help you practice: datacarpentry.org/semester-bi...

Комментарии • 60

  • @jannonflores1113
    @jannonflores1113 2 года назад +5

    I purchased a freakin course in R and I had trouble understanding this one topic. Well, I found your topic here on youtube and it was well explained in a 12 minute video. Props to you man..... Thanks a lot

    • @weecology
      @weecology  2 года назад +1

      Thanks! Functions are definitely tricky and it's taken me years of iteration to get to that 12 minutes so I'm very glad that it's useful.

  • @epijournal8423
    @epijournal8423 3 года назад +7

    A very clear video ! There are few tutorial on function building on RUclips.
    Going to go through the others now :)
    Cheers.

  • @jacksfacts20
    @jacksfacts20 2 года назад +3

    First I wanna say thank you for this very informative video, 2nd, As a small youtuber myself, the fact that you did a lot of this in one take is impressive and tough to do. From personal experience, you can make it a lot easier on yourself by breaking up what your saying into small chunks that you can cut together. That why you don't have to worry about awkward pauses as much. People don't mind cuts of you speaking if they're in logical places like the end of sentences and such.

  • @GurpreetSingh-uj6bq
    @GurpreetSingh-uj6bq 2 года назад +1

    One of The best videos I ever watched on functions

  • @rayraystinz
    @rayraystinz 2 года назад

    this was incredibly clear, helpful and I appreciate the format! nice to see a human face (instead of just the typical voiceovers)

    • @weecology
      @weecology  2 года назад

      So glad it was useful!

  • @shotpana
    @shotpana 2 года назад +1

    Thank you! You are an amazing professor!

    • @weecology
      @weecology  2 года назад

      So glad it's helpful!

  • @quantowen1124
    @quantowen1124 2 года назад +1

    This was extremely helpful! Love it!

    • @weecology
      @weecology  2 года назад +1

      So glad it was useful!

  • @aayushimittal5270
    @aayushimittal5270 3 года назад +1

    Awesome video...
    Thanks to you I finally know the meaning of curly brackets

    • @weecology
      @weecology  3 года назад

      Soo glad it was helpful!

  • @karanthakker2672
    @karanthakker2672 Год назад +1

    This is a fantastic tutorial!
    Keep it up, you've earned a sub :)

  • @timmytesla9655
    @timmytesla9655 2 года назад +1

    This is super clear. Thank you!

  • @jaclynjuarez9289
    @jaclynjuarez9289 3 года назад

    Thank you for this video. It really helped with my studies. Your explanation made it easy to understand functions in r

    • @weecology
      @weecology  3 года назад

      Awesome! Very glad it was helpful.

  • @donniemarshall2531
    @donniemarshall2531 Год назад

    Thank You! This helped my learning curve tremendously. You are an awsome teacher! and singer!

    • @weecology
      @weecology  Год назад

      Thanks! So glad it’s helpful!

  • @mitch6151
    @mitch6151 Месяц назад

    Clear! Great!

  • @rehab4e2
    @rehab4e2 2 года назад

    Thank you so much for the video. It's really helpful for me! I got it. And I can write some functions for myself!

    • @weecology
      @weecology  2 года назад +1

      That's awesome! Glad to hear it!

  • @tatianam7657
    @tatianam7657 Год назад

    Excellent!

  • @KameshwarChoppella
    @KameshwarChoppella Год назад

    Very well explained. I'm likely coming back to this channel. Subbed

  • @Samyak_Patil
    @Samyak_Patil 2 года назад

    Thank you so much. You made it super easy.

    • @weecology
      @weecology  2 года назад

      Glad it was helpful!

  • @da8804ss
    @da8804ss 2 года назад

    great explanation

  • @multitaskprueba1
    @multitaskprueba1 2 года назад

    You are a genius! Thank you!

  • @gsalem7351
    @gsalem7351 3 года назад

    Thank you

  • @ckeong9012
    @ckeong9012 3 года назад

    clear. tq sir

  • @auracristinareynavarro2523
    @auracristinareynavarro2523 3 года назад

    great!

  • @willatkinson141
    @willatkinson141 3 года назад +1

    How would you go about returning more than one calculation at a time for the same function? Great video.

    • @weecology
      @weecology  3 года назад +1

      That's a great question. Typically if you want to return more than one value you pass those values back in a single object that can store multiple values. Most commonly this would be a list, but it could also be a vector or something else. In the function you create a list that holds each of the things you want to return and then return the list at the end.

  • @krushnachChandra
    @krushnachChandra 3 года назад

    helpful video you got new sub

  • @andreasioannides3868
    @andreasioannides3868 2 года назад

    Hi sir im a student and i have a question that tells me to construct a function with two arguments A and u that return only the non zero entries of a vector E. Vector E has length 25000 and is defined as E=max(A-u, 0) i have already build a function for vector A in a previous part. i desperately need help thank you

  • @rishabhkansal3309
    @rishabhkansal3309 Год назад

    much useful

  • @Skyking8383
    @Skyking8383 Год назад

    How would you create a function in order to create a time series plot? I am not sure what information you would put

  • @bismaarshad280
    @bismaarshad280 8 месяцев назад

    OMG! THANKSSSS MANNNN!

    • @weecology
      @weecology  8 месяцев назад

      You’re welcome!

  • @taiwolawal9687
    @taiwolawal9687 2 года назад

    this was super helpful, what if i want the function to take input from a sequence say example output of test

    • @weecology
      @weecology  2 года назад

      You can pass any object to a function, so you can certainly pass test as an argument in this case. Then inside the function you treat test however you would outside of the function. Any operations that work on sequences can be used inside the function.

  • @aniladeepu8999
    @aniladeepu8999 2 года назад

    sir, how to integrate the following function in r using limits -Infinity to x.
    f1

  • @divyabadlia5830
    @divyabadlia5830 Месяц назад

    Whenever I try to change line after using braces to write function body I can't seem to do it
    I can't seem to separate those braces can anyone help me with this

  • @redrosin99
    @redrosin99 2 года назад

    Your explanation is very good however I would like to know: 1. Which editor are you using?
    2. Where in memory should I save the function (as a separate R file) and how should I let R know about its existence (does it have to be loaded as a package or do I have a workspace?)

    • @weecology
      @weecology  2 года назад +1

      The video uses RStudio, which is the most common development environment for R.
      For small projects I recommend just keeping the function in the same R file as the rest of your code. Just put all of the functions at the top of the code (after loading any packages but before any code that isn't in functions) and then all the functions in the code. If it's a bigger project you can put one or more functions into one or more separate R files. To let R know about them at the top of your code you run `source("/path/to/yourfile.R")`. This will run all of the code in that file and so if that file is just functions it will define all of those functions so that you can use them.

    • @redrosin99
      @redrosin99 2 года назад

      @@weecology thank you for your answer and for your great videos!!

    • @weecology
      @weecology  2 года назад

      @@redrosin99 You're welcome!

  • @asadkhanbb
    @asadkhanbb Год назад

    ❣️❣️❣️

  • @carlyap5943
    @carlyap5943 2 года назад +1

    AYOS YAN PRE PALIKE

  • @Oluwaseun_Adeyemi
    @Oluwaseun_Adeyemi 2 года назад

    how can I write a function to calculate kurtosis?

    • @weecology
      @weecology  2 года назад

      The input value to your function would be a vector of the values that you want to use for the kurtosis calculation. You would then calculate the kurtosis for that vector, which is something like mean((values - mean(values)) / sqrt(var(values))) (I haven't checked this so you should make sure it matches en.wikipedia.org/wiki/Kurtosis and works. This functionality is also available in a bunch of packages including the moments package cran.r-project.org/web/packages/moments/index.html

  • @gabrielamendezospino6415
    @gabrielamendezospino6415 Год назад

    Hi, I get the error object 'lenght' not found when trying to call the function, I image it's because there should be a dataset with the variable of that name, right?

    • @weecology
      @weecology  Год назад

      Looks like maybe you just have a typo. The way I wrote it It's 'length' not 'lenght'. All that actually matters is that it is the same in the parentheses and in the body of the function.

  • @theunitydev5418
    @theunitydev5418 2 года назад

    As someone that knows how to code this hurts to watch and learn and its most definetly not your fault but Rs. Who came up with the idea of not having to define the type of variable you are using shit get confusing fast

  • @richardsmith9399
    @richardsmith9399 2 года назад

    Good talk, but you a goofy lookin dude. Thanks man!