1 / 37

Introduction

Introduction. Session 1. R as a Giant Calculator. Demo: Set 1. Now try it yourself. log(), exp (), log10(), sqrt (), factorial(), choose(), floor(), ceiling(), trunc (), round(), signif (), cos (), sin(), tan(), acos (), asin (), atan (), acosh (), asinh (), atanh ()

base
Download Presentation

Introduction

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction Session 1

  2. R as a Giant Calculator

  3. Demo: Set 1

  4. Now try it yourself log(), exp(), log10(), sqrt(), factorial(), choose(), floor(), ceiling(), trunc(), round(), signif(), cos(), sin(), tan(), acos(), asin(), atan(), acosh(), asinh(), atanh() Use help() to figure out what these functions do, and play with them

  5. What is Programming Exactly

  6. According to Wikipedia, Computer programming (often shortened to programming, scripting, or coding) is the process of designing, writing, testing, debugging, and maintaining the source code of computer programs. This source code is written in one or more programming languages (such as Java, C++, C#, Python, etc.). The purpose of programming is to create a set of instructions that computers use to perform specific operations or to exhibit desired behaviors. The process of writing source code often requires expertise in many different subjects, including knowledge of the application domain, specialized algorithms and formal logic. Within software engineering, programming (the implementation) is regarded as one phase in a software development process.

  7. According to Wikipedia, Computer programming (often shortened to programming, scripting, or coding) is the process of designing, writing, testing, debugging, and maintaining the source code of computer programs. This source code is written in one or more programming languages (such as Java, C++, C#, Python, etc.). The purpose of programming is to create a set of instructions that computers use to perform specific operations or to exhibit desired behaviors. The process of writing source code often requires expertise in many different subjects, including knowledge of the application domain, specialized algorithms and formal logic. Within software engineering, programming (the implementation) is regarded as one phase in a software development process.

  8. But we’re not software engineers Computer programming (often shortened to programming, scripting, or coding) is the process of designing, writing, testing, debugging, and maintaining the source code of computer programs. This source code is written in one or more programming languages (such as Java, C++, C#, Python, etc.). The purpose of programming is to create a set of instructions that computers use to perform specific operations or to exhibit desired behaviors. The process of writing source code often requires expertise in many different subjects, including knowledge of the application domain, specialized algorithms and formal logic. Within software engineering, programming (the implementation) is regarded as one phase in a software development process.

  9. In other words, • A program is plan of action, or a story • And programming is the creative process of making the plan or writing the story

  10. Elements of a storyvs.Elements of a Program

  11. Hypothetical Program/Passage You don’t need to be able to understand all of the following. Just read it for now and think about it.

  12. Christmas Shopping • A hypothetical program • Alice needs to buy Christmas Presents for each of her cousins so • She’s planning out her day • So her plan, which she calls OperationXMas() should take in input a list of her 8 cousins • And output a list of wrapped presents Carl Bob Dee

  13. Christmas Shopping Human language (what Alice is thinking in her mind): My cousins are Bob, Carl, & Dee Start out with no items bought For each person, pick out a perfect present Checking out all items in my shopping cart Bring home what I bought Programming Language (if Alice wanted to hire a robot to do her bidding): Cousins = c(Bob, Carl, Dee) cart = c() for(each in Cousins){ cart = c(cart, PickPresent(each)) } cart = CheckOut(cart) return(cart)

  14. R • R is programming language designed for statistical computing, graphics, and data analysis • It’s open source, meaning that the source code is also is freely accessible. So the benefit is that it’s free, and easily updated with new methods and techniques

  15. What We’ll Be Doing

  16. Demo 1: Introduction • This will be a gentle ease in • It won’t be extremely fun, but I believe that once you stick this out, the rest will be a lot more understandable and interesting

  17. Demo 2: Data and Graphics Google Flu Trends Data Sources: http://www.google.org/flutrends/us/data.txt http://www.cdc.gov/flu/weekly/ussurvdata.htm

  18. Demo 3: Working With Packages and a Bit of Math Radiohead Data Source: http://code.google.com/p/radiohead/

  19. Demo 3: String Processing, Web Scraping, and Large Datasets State of the Union Addresses Data Source: http://www.presidency.ucsb.edu/sou.php

  20. Demo 4: Mark Up Languages Flu Activity Using XML

  21. Demo 4: Mark Up Languages Or Alternatively: Make a Website Using HTML

  22. Other Demos (to be planned…) • Unix and Remote Computing May use Amazon Cloud for this Demo, but I know a few of you also have Biowulf accounts, so that would be easier • Python Tutorial This will also be a bit dry, but the exciting part is that you should now be able to learn a new language very quickly • Introductory Sequence Processing If you’re interested in genomics, this will be fun, and even if you’re not, I think this can also be fun. • Search Algorithms This is more theoretical, but it still is useful. I’ve had to whip this out of my toolkit a couple times this year. I think it’s really fun, though you can tell me if you think I’m lying. And we can demo this through searching mazes. • Suggestions?

  23. Variables, Primitive Data Types, Data Structures, and Functions

  24. Variables • Names, same as in life, for example, Alice, Bob, Carol, Fluffy • They “store” data • In this illustration, the variables are the name cups, not the actual people themselves. Alice apple dog

  25. Primitive Data Types • Primitive data types serve as the fundamental building blocks for more complicated types of data. • As a real-world analogy, I relate data to nouns, and primitive data to anything organic, occurring naturally like apples, dogs, people

  26. Primitive Data Types in R • R has three main primitive data types • Numeric (numbers, ex: 0, 5, 144, 25.7, Inf) • Character (words or passages, ex: “hello world”, “apple”, “My fellow citizens, I stand here today humbled by the task before us”) • Logical (TRUE/FALSE) • There is one exception, missing data is represented as NA and has certain properties of its own

  27. Logical Data • Also called “boolean” data • In R, it is represented as TRUE/FALSE • But it can also be represented as 1/0

  28. OR • Alice is trying to pick out a gift for Bob • Bob wants either something red OR a pen • Will he be happy with • A red pen? • A red candle? • A blue pen? • A blue candle?

  29. OR Gift Is it red? Is it a pen? Happy? red pen TRUE TRUE TRUE red candle TRUE FALSE TRUE blue pen FALSE TRUE TRUE blue candle FALSE FALSE FALSE

  30. AND • Alice is trying to pick out a gift for Bob • Bob wants either something red AND a pen • Will he be happy with • A red pen? • A red candle? • A blue pen? • A blue candle?

  31. AND Gift Is it red? Is it a pen? Happy? red pen TRUE TRUE TRUE red candle TRUE FALSE FALSE blue pen FALSE TRUE FALSE blue candle FALSE FALSE FALSE

  32. Demo: Next time

  33. Christmas Shopping • A hypothetical program • Alice needs to buy Christmas Presents for each of her cousins so • She’s planning out her day • So her plan, which she calls OperationXMas() should take in input a list of her 8 cousins • And output a list of wrapped presents Carl Bob Dee

  34. Christmas Shopping Human language (what Alice is thinking in her mind): My cousins are Bob, Carl, & Dee Start out with no items bought For each person, pick out a perfect present Checking out all items in my shopping cart Bring home what I bought Programming Language (if Alice wanted to hire a robot to do her bidding): Cousins = c(Bob, Carl, Dee) cart = c() for(each in Cousins){ cart = c(cart, PickPresent(each)) } cart = CheckOut(cart) return(cart)

  35. Generate the first N Fibonacci #s 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ... The nth Fibonacci number is the sum of the previous two numbers. In other words, Fn=Fn-1+Fn-2 F0=0, F1=1

  36. Generate the first N Fibonacci #s 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ... The nth Fibonacci number is the sum of the previous two numbers. In other words, Fn=Fn-1+Fn-2 F0=0, F1=1

  37. Generate the first N Fibonacci #s Human language: Generating a list of the first n Fibonacci numbers involves knowing what the value of “n” is. Creating an empty vector called myFibs with n spots Fill spot 1 with 0 and spot 2 with 1 For each spot number, starting with 3, and ending with n, fill that spot with the sum of what’s in the previous two spots Output the list of numbers Programming Language: fibonacci = function(n){ myFibs = rep(0,n) myFibs[1] = 0 myFibs[2] = 1 for(spot in 3:n){ myFibs[spot] = myFibs[spot-1] + myFibs[spot-2] } return(myFibs) }

More Related