R for Stata Users

R for Stata Users

von: Robert A. Muenchen, Joseph M. Hilbe

Springer-Verlag, 2010

ISBN: 9781441913180

Sprache: Englisch

549 Seiten, Download: 7459 KB

 
Format:  PDF, auch als Online-Lesen

geeignet für: Apple iPad, Android Tablet PC's Online-Lesen PC, MAC, Laptop


 

eBook anfordern

Mehr zum Inhalt

R for Stata Users



"5 Programming Language Basics (p. 45-46)

5.1 Introduction

R is an object-oriented language. Everything that exists in it — variables, data sets, functions (commands) — are all objects. Stata has limitations on command and variable name lengths, based on the version of the software being used. The limits are large, though, and rarely result in a problem for Stata users. In Stata, leading periods in names are not allowed and data set names cannot have periods at all. Object names in R can be any length consisting of letters, numbers, underscores “ ,” or the period “.” and should begin with a letter. However, in R if you always put quotes around a variable or data set name (actually any object name), it can then contain any characters, including spaces.

Case matters in both R and Stata, so you can have two variables—one named myvar and another named MyVar—in the same data set, although that is not a good idea! Some add-on packages tweak function names like the capitalized “Save” to represent a compatible, but enhanced, version of a built-in function like the lowercased “save.” As in any statistics package, it is best to avoid names that match function names like “mean” or that match logical conditions like “TRUE.”

Commands can begin and end anywhere on a line and R will ignore any additional spaces. R will try to execute a function when it reaches the end of a line. Therefore, to continue a function call on a new line, you must ensure that the fragment you leave behind is not already a complete function call by itself. Continuing a function call on a new line after a comma is usually a safe bet. As you will see, R functions frequently use commas, making them a convenient stopping point.

The R console will tell you that it is continuing a line when it changes the prompt from “>” to “+.” If you see “+” unexpectedly, you may have simply forgotten to add the ?nal close parenthesis, “).” Submitting only that character will then ?nish your function call. If you are getting the “+” and cannot ?gure out why, you can cancel the pending function call with the Escape key on Windows or CTRL-C on Macintosh or Linux/UNIX. For CTRL-C, hold the CTRL key down (Linux/UNIX) or the control key (Macintosh) while pressing the letter C. You may end any R function call with a semicolon. That is not required though, except when entering multiple function calls on a single line."

Kategorien

Service

Info/Kontakt