+ Reply to Thread
Page 2 of 27 FirstFirst 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ... LastLast
Results 16 to 30 of 392

Thread: Today I Learned: ____

  1. #16
    R purist
    Points: 35,103, Level: 100
    Level completed: 0%, Points required for next Level: 0
    TheEcologist's Avatar
    Location
    United States
    Posts
    1,921
    Thanks
    303
    Thanked 608 Times in 341 Posts

    Re: Today I Learned: ____




    Quote Originally Posted by Dason View Post
    And please tell me your linux username isn't actually ggplothater.
    It might be ;-)
    The true ideals of great philosophies always seem to get lost somewhere along the road..

  2. #17
    Devorador de queso
    Points: 97,539, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Posting AwardCommunity AwardDiscussion EnderFrequent PosterActivity Award
    Dason's Avatar
    Location
    Tampa, FL
    Posts
    12,987
    Thanks
    309
    Thanked 2,640 Times in 2,255 Posts

    Re: Today I Learned: ____

    Ever run a function/simulation that takes a long time and after it's done you realize that you didn't save it to a variable so you can't process it any further?
    Code: 
    takes.a.while <- function(){
      Sys.sleep(10)
      rnorm(20)
    }
    
    takes.a.while()
    That would be really annoying if there was no way to get at that information! Oh wait there is!
    Code: 
    # Oh no I forgot to assign it to a variable
    lifesaver <- .Last.value
    lifesaver
    .Last.value contains the value of the last top level expression.

    TIL: .Last.value is your friend.

  3. The Following 4 Users Say Thank You to Dason For This Useful Post:

    bryangoodrich (01-04-2012), jpkelley (01-04-2012), Trillian (10-30-2012), trinker (01-04-2012)

  4. #18
    Probably A Mammal
    Points: 32,065, Level: 100
    Level completed: 0%, Points required for next Level: 0
    bryangoodrich's Avatar
    Location
    Sacramento, California, United States
    Posts
    2,567
    Thanks
    398
    Thanked 618 Times in 551 Posts

    Re: Today I Learned: ____

    Okay, I think it's time to just see the list of internal variables R has hiding around already! lol

  5. #19
    Probably A Mammal
    Points: 32,065, Level: 100
    Level completed: 0%, Points required for next Level: 0
    bryangoodrich's Avatar
    Location
    Sacramento, California, United States
    Posts
    2,567
    Thanks
    398
    Thanked 618 Times in 551 Posts

    Re: Today I Learned: ____

    While this is not something I learned today, nor does it apply specifically to R, I thought it would be worth sharing for those that are interested. I know I was jubilant about it when I discovered it.

    If you have your own web page, especially a Wordpress, then you have access to displaying your code in a very formal way making it easier to present, reference, and access your code online. The use of a Syntax Highlighter will put your unformatted code into its own display box with line numbers and proper alignment. A good one that is an easy plug-in to Wordpress is SyntaxHighlighter Evolved. It has rules on how to color code key words for a variety of languages. It is easy to implement. It also has a lot of options such as specifying which line numbers to highlight in a given display, whether line numbers should be shown, or whether a given code box should be collapsed (with the option to expand) on page load; this is similar to our "spoiler" tag here.

    I've started using it. I'm going to eventually get around to creating a page for my ALSM project that includes my code for each chapter collapsed into their own boxes as part of its TOC. That way, it is easy to view my code and if someone wants the R script, they can download it from a link. Alternatively, I might give each chapter its own page and have each section collapse. I haven't decided. It is just one example where a bulk presentation of code can be made very easy to present, and I'll probably prepare the html I'll include beforehand since it'll mostly be the code with parts of it trapped between [sourcecode language='r'] ... code here ... [/sourcecode] tags.

    Very cool? I think so!

  6. #20
    Devorador de queso
    Points: 97,539, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Posting AwardCommunity AwardDiscussion EnderFrequent PosterActivity Award
    Dason's Avatar
    Location
    Tampa, FL
    Posts
    12,987
    Thanks
    309
    Thanked 2,640 Times in 2,255 Posts

    Re: Today I Learned: ____

    I just tried copying some of the code from here. And the line numbers get copied as well. Is there a way to not have it copy the line numbers?

  7. #21
    Probably A Mammal
    Points: 32,065, Level: 100
    Level completed: 0%, Points required for next Level: 0
    bryangoodrich's Avatar
    Location
    Sacramento, California, United States
    Posts
    2,567
    Thanks
    398
    Thanked 618 Times in 551 Posts

    Re: Today I Learned: ____

    Yeah, don't copy the whole **** thing! It depends on where you start grabbing. The HTML is literally a sequence of numbers and then the code. If you highlight too much to copy, you'll grab the sequence of numbers.

  8. #22
    ggplot2orBust
    Points: 72,900, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    User with most referrers
    trinker's Avatar
    Location
    Buffalo, NY
    Posts
    4,424
    Thanks
    1,815
    Thanked 931 Times in 812 Posts

    Re: Today I Learned: ____

    Just used that .Last.value function.
    "If you torture the data long enough it will eventually confess."
    -Ronald Harry Coase -

  9. #23
    Devorador de queso
    Points: 97,539, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Posting AwardCommunity AwardDiscussion EnderFrequent PosterActivity Award
    Dason's Avatar
    Location
    Tampa, FL
    Posts
    12,987
    Thanks
    309
    Thanked 2,640 Times in 2,255 Posts

    Re: Today I Learned: ____

    It's not technically a function but an interval variable that every top level function stores their output to before returning it to the user.

  10. The Following User Says Thank You to Dason For This Useful Post:

    trinker (12-14-2013)

  11. #24
    ggplot2orBust
    Points: 72,900, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    User with most referrers
    trinker's Avatar
    Location
    Buffalo, NY
    Posts
    4,424
    Thanks
    1,815
    Thanked 931 Times in 812 Posts

    Re: Today I Learned: ____

    This is so simple and how dummy coding works but I never thought about using mean to find proportions of something. Today Dason added to a post I gave to an R user about find proportions of a value and his code was much simpler and faster.

    Code: 
    x <- rnorm(1000, 5, 1.75)
    sum(x > 0)/length(x) #gives the proportion using binary operator
    mean(x > 0)  #Dason way that also gives the proportion using binary operator
    
         test replications elapsed relative user.self sys.self user.child sys.child
    2   dason       100000    3.46 1.362205      3.13     0.00         NA        NA
    1 trinker       100000    2.54 1.000000      2.11     0.07         NA        NA
    "If you torture the data long enough it will eventually confess."
    -Ronald Harry Coase -

  12. #25
    Devorador de queso
    Points: 97,539, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Posting AwardCommunity AwardDiscussion EnderFrequent PosterActivity Award
    Dason's Avatar
    Location
    Tampa, FL
    Posts
    12,987
    Thanks
    309
    Thanked 2,640 Times in 2,255 Posts

    Re: Today I Learned: ____

    Quote Originally Posted by trinker View Post
    This is so simple and how dummy coding works but I never thought about using mean to find proportions of something. Today Dason added to a post I gave to an R user about find proportions of a value and his code was much simpler and faster.
    It is simpler to write and less code (so faster to write too) but interestingly enough as your output shows using mean actually is a performance hit. I wouldn't have guessed that.

  13. #26
    Devorador de queso
    Points: 97,539, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Posting AwardCommunity AwardDiscussion EnderFrequent PosterActivity Award
    Dason's Avatar
    Location
    Tampa, FL
    Posts
    12,987
    Thanks
    309
    Thanked 2,640 Times in 2,255 Posts

    Re: Today I Learned: ____

    TIL: RStudio has a neat little way to add some gWidgets type functionality to plots through their own library (only available if using RStudio).

    http://www.rstudio.org/docs/advanced/manipulate

  14. The Following 3 Users Say Thank You to Dason For This Useful Post:

    bryangoodrich (01-07-2012), Trillian (10-30-2012), trinker (01-07-2012)

  15. #27
    TS Contributor
    Points: 13,936, Level: 76
    Level completed: 72%, Points required for next Level: 114
    jpkelley's Avatar
    Location
    Vancouver, BC, Canada
    Posts
    440
    Thanks
    17
    Thanked 90 Times in 84 Posts

    Re: Today I Learned: ____

    Why hadn't I seen this before...

    In lattice graphics, it's easy to save a plot as an object. I was previously unaware of something similar in base graphics (but I'm sure you all have). Anyway, a convenient little gem of a function. Use after making your plot as such...

    Code: 
    plotname<-recordPlot()

  16. The Following 2 Users Say Thank You to jpkelley For This Useful Post:

    Trillian (10-30-2012), trinker (01-10-2012)

  17. #28
    TS Contributor
    Points: 13,936, Level: 76
    Level completed: 72%, Points required for next Level: 114
    jpkelley's Avatar
    Location
    Vancouver, BC, Canada
    Posts
    440
    Thanks
    17
    Thanked 90 Times in 84 Posts

    Re: Today I Learned: ____

    Although I won't post code, I also learned today how to interpret (and use) model-averaging for Generalized Additive Models (package mgcv). Once I sat down with it, it was relatively simple. Allowed me to examine exactly which parts of my 3-D selection surfaces had a positive or negative effect (by examining confidence intervals on the link scale). Model-selection and model-averaging with GAM and GAMM is a bee-otch.

    Anyway, just needed to tell someone about the small steps made today!

  18. #29
    Phineas Packard
    Points: 16,013, Level: 81
    Level completed: 33%, Points required for next Level: 337
    Lazar's Avatar
    Location
    Sydney
    Posts
    1,159
    Thanks
    198
    Thanked 336 Times in 299 Posts

    Re: Today I Learned: ____

    TIL: To my horror ...... that base is more flexible and potentially useful than ggplots.

  19. #30
    TS Contributor
    Points: 13,936, Level: 76
    Level completed: 72%, Points required for next Level: 114
    jpkelley's Avatar
    Location
    Vancouver, BC, Canada
    Posts
    440
    Thanks
    17
    Thanked 90 Times in 84 Posts

    Re: Today I Learned: ____


    Ha...well said. I just don't like having to deal with more than one syntax for simple tasks. I like ggplot2, but I think I'm going to stay in the base world and build a better foundation there.

    R.I.P. for now ggplot2.

+ Reply to Thread
Page 2 of 27 FirstFirst 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ... LastLast

           




Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts






Advertise on Talk Stats