![]() ![]() To assign a value to a variable, one can use either the "=" or " x x There are also some reserved words that can not be used: 2way" would not be valid, while way_2 would be just fine. ![]() They must start with a letter or a dot not followed by a number. Valid names consist of letters, numbers, and the dot (period) or underline characters. In R, there are some limitations to the variable names one can use. When we assign a value to a variable, we are essentially storing that value in the corresponding box. You can think of a variable as a box with a particular name. The value of an expression can be assigned to a variable for later use. Try it! Working with Variables and Simple Data As such, we might type " ?log" at a prompt, whereby we will be presented with an entire web page detailing everything we might want to know about the log function and all its variants and related functions. So for example, suppose we were interested in finding out how to change the base for the log function from the default $e$ to some other value. More information on any of these functions can be found by typing the function name preceded by a "?" character. The following example calculates the value of $$\sin 3\pi/2 + \ln e^5 - \sqrt$$ For example, one may wish to create an expression involving square roots, trigonometric functions, or logarithms. In addition to the simple operators and constants discussed above, R has many, many functions that one can use to build more complicates expressions. To use $\pi$ in an expression, for example, one just types " pi": R is aware of some important mathematical constants. When doing so, order of operations are preserved - that is to say, things inside parentheses are evaluated first, multiplication and division happen before addition or subtraction, exponentiation happens before multiplication or division, and so on. We can combine multiple operations into a single mathematical expression, of course. The %%, on the other hand, outputs just the remainder of the related quotient. The %/% above performs the operation of integer division, which is identical to regular division, except it throws away any remainder. R also supports some arithmetic operations you may not have known about. R supports all of the regular arithmetic operators (addition, subtraction, multiplication, and division). ![]() The "" in this case simply means that the "2" seen to its immediate right is the first value output in response to "1+1". Some input expressions we will deal with later can cause R to produce many, many values in response. Simply type 1+1 at the prompt, and hit enter to see the answer:įor the moment, you can ignore the "" that precedes the answer of "2". Suppose you want R to perform a simple addition problem, like $1 + 1$. While R is well more powerful than a scientific calculator, it can certainly function as one, when desired. Then you get another prompt, and the process starts all over again. Upon typing some command or expression, R produces some response. When you start R (or R Studio), you are presented with a prompt - an invitation to say something to R. You can think of working with R as a conversation. As such, even today, they are frequently the programs of choice for the power users and computer gurus of the world. Text-based programs, on the other hand, generally have a steeper learning curve - but they also offer tremendous flexibility, application, and speed. Instead, they use programs that provide intuitive and easy-to-use graphical user interfaces (GUIs), full of windows, colorful icons, buttons, etc. Indeed, the great masses of computer users rarely run text-based programs anymore. Without an additional integrated development environment (IDE) like R Studio, it doesn't even recognize the mouse!Īn entirely text-based application may seem like a throw-back to the days of old when MS-DOS ruled the world, and Apple and Windows operating systems were still finding their footings. While most all of our efforts will be confined to using R through RStudio, the point of bringing up these other ways of working with R is to emphasize that R, by itself, is entirely text-based. Below is a picture of what working with R inside OS X's "Terminal" program looks like: For those that wish to do so, you can launch and use R with just a simple "Terminal" application under OS X, or the "Windows Subsystem for Linux" under Windows. However, this front end is not a necessity. ![]() RStudio provides a nice "front end" for R, adding to the console environment other windows to keep track of files, images, variable values, etc. R is a program designed to run in a terminal or console environment. R Calculations, Variables, and Simple Data Sets The Text-Based Nature of R R Calculations, Variables, and Simple Data Sets ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |