Assignments and basic operations in R

From AWF-Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "An assignment is the fact of storing an object under a given name. Assignments in <math>\textsf{R}</math> are done by using the "arrow" ({\tt <-}) or the equal ({\tt =}) symbo...")
 
(Replaced content with "{{construction}}")
 
Line 1: Line 1:
An assignment is the fact of storing an object under a given name. Assignments in <math>\textsf{R}</math> are done by using the "arrow" ({\tt <-}) or the equal ({\tt =}) symbol, even though it can be recommended to use the arrow because some functions use the equal symbol as an argument. Assignments can be done in two directions. Some examples are shown below.
+
{{construction}}
<<>>=
+
a <- 2
+
b <- 3
+
4 -> c
+
a
+
b
+
c
+
@
+
Operating with objects in \textsf{R} is very easy. Below some examples with single values:
+
<<>>=
+
(a+b)/c*5
+
@
+
 
+
and with vectors.
+
<<>>=
+
v.1 <- v*exp((a+b)/c*5)
+
v.1
+
@
+
Note that in the first case the calculus was computed and displayed in the console, but the result was not assigned to any object. In the second case, the result of the calculus was assigned to a new object named {\tt v.1}. In the assignment process it must be considered that objects can be overwritten as many times as we want, and the information of the original object can be lost if the required attention is not played.
+
 
+
Assignments can also be done to positions in an existent object. In the following example, the values in the third column of the data frame {\tt d} are replaced by the characters {\tt "low"}, {\tt "medium"} and {\tt "high"} as follows:
+
<<>>=
+
d$C <- c("low", "medium", "high")
+
d
+
@
+
The assignments can also be to a previously non-existent column in the dataframe.
+
<<>>=
+
d$E <- m[,3]
+
d
+
@
+
 
+
Logical tests can also be done in \testsf{R}.
+
<<>>=
+
e <- c<a
+
e
+
@
+

Latest revision as of 10:52, 6 November 2014

Construction.png sorry: 

This section is still under construction! This article was last modified on 11/6/2014. If you have comments please use the Discussion page or contribute to the article!

Personal tools
Namespaces

Variants
Actions
Navigation
Development
Toolbox
Print/export