R Programming - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

R Basic Example

R Basic Example

shape Description

The programming syntax for the R programming is very simple when compared to other languages and every coding language will have variables and functions etc. To go with basic example user need to have knowledge on some basic fundamentals of the programming elements such as varibles, data types, functions, objects.

Programming Elements

shape Description

Every coding language will have the following elements.

Data Types

Every programming language consists of some kind of data. Datatype shows the specific data entered into a program. The data types are the keywords used to declare the type of the variable used in the program such as integer, real, character and string. The following is an example, where splessons is the data type. [c]splessons<-'Start Thinking Start Coding'[/c]

Variables

The different memory locations where data resides are called objects. To access such an object it must have a name, and such a named object is called a Variable. The information stored inside an object is called as a value. Of course the machine itself typically has no idea how to interpret the information it contains, but the program certainly needs to know. For this reason a variable has a specific type. And it’s this type that constrains the use of that variable, such that only operations appropriate to the type may be performed. The following is an example, where x is the variable and the value of the variable is 10. [c]x<-10[/c]

Functions

Functions can be defined as a partitioned blocks of code in a program, which can be called any number of times during single execution of a program. Functions reduces the memory and complexity of the program. The following is the syntax for the functions in R programming langugae. [c]function_name <- function(arg_1, arg_2, ...) { Function body }[/c]

Strings

Strings resemble sentences. Strings are shaped by a rundown of characters, which is truly a variety of characters. Strings are extremely valuable when conveying data from the program to the client of the program. They are less valuable while putting away data for the PC to utilize. The following is an example for the strings. [c]a <- 'Welcome To SPlessons' print(a)[/c]

Operator

Operators are one of the pillar blocks in any programming language. Typically an Operator can work on one or more objects, also known as Operands, and it will return some of the results.

shape Example

The following is an example to understand how to start a programming in R programming language. [c] > splessons<-'Start Thinking Start Coding' > print(splessons) [1] "Start Thinking Start Coding" [/c] In the above example, splessons is the string data type that stores the string data that is Start Thinking Start Coding. Where print is used to display the data on the console. The user can save file with an extension of .R .

Summary

shape Key Points

  • In R programming comments can be placed with the # tag.
  • The R programming language can not support multi line comments.
  • An interpreter doe not take care about comments that means memory is not allotted.