 Subscribe via RSS

Login
Archives
 October 2014 (1)
 December 2013 (1)
 October 2013 (2)
 September 2013 (2)
Tag Cloud
Animation (2) CSP (2) Data (8) Data Science (3) Distributions (1) Dust (5) Economics (6) Engineering (2) Equipment Venders (1) Faster R (1) GDAL (4) Germany (1) ggplot2 (2) GIS (4) Irradiance (3) Kuwait (1) LaTeX (1) Linux (1) Meteorology (5) Misc Tricks (1) Modeling (2) Natural Gas (2) Nuclear (1) O&M (2) Projects (4) Project Valuations (5) Qatar RE (12) R Colors (1) R Data Import (4) R Data Objects (16) R Data Syntax (6) Renewable Energy (8) RE Policy (3) Resource Assessment (6) R Graphics (5) R Packages (2) R Programming (6) Saudi Arabia (2) Scientific Computing (1) Solar (17) Spatial Analysis (4) UAE (2) Ubuntu (1) Website (1) Wind (3)Rbloggers
PV Insider
EIA – Today in Energy
Renewable Energy World
Category Archives: R Data Syntax
Data Concatenation and Coercion in R
Data concatenation and coercion are common operations in R.
Data Concatenation
The concatenate c() function is used to combine elements into a vector.
1 2 3 4 5 
> c(T, F, T) [1] T F T > c(8.3, 9.2, 11) [1] 8.3 9.2 11.0 
When elements are combined from different classes, the c() function coerces to a common type, which is the type of the returned value:
1 2 3 4 
> x < c(100, "A", TRUE, as(1, "complex")) > x [1] "100" "A" "TRUE" "1+0i" > class(x) [1] "character" 
Posted in R Data Objects, R Data Syntax
Leave a comment
Data Infix Operators in R
Intro to Infix Operators in R
Infix operators in R are unique functions and methods that facilitate basic data expressions or transformations.
Infix refers to the placement of the arithmetic operator between variables. For example, an infix operation is given by (a+b), whereas prefix and postfix operators are given by (+ab) and (ab+), respectively.
The types of infix operators used in R include functions for data extraction, arithmetic, sequences, comparison, logical testing, variable assignments, and custom data functions.
Posted in R Data Syntax
Leave a comment
Data Formatting in R
There are a number of ways to accomplish data formatting in R.
Data Options in R
R supports a range of data formats and controls. The options() function accesses the default settings R establishes at startup. Session options that can be changed from the command line include:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 
> names(options()) [1] "add.smooth" "bitmapType" "browser" [4] "browserNLdisabled" "check.bounds" "continue" [7] "contrasts" "defaultPackages" "demo.ask" [10] "device" "device.ask.default" "digits" [13] "dvipscmd" "echo" "editor" [16] "encoding" "example.ask" "expressions" [19] "help_type" "help.search.types" "help.try.all.packages" [22] "HTTPUserAgent" "internet.info" "keep.source" [25] "keep.source.pkgs" "locatorBell" "mailer" [28] "max.print" "menu.graphics" "na.action" [31] "nwarnings" "OutDec" "pager" [34] "papersize" "pdfviewer" "pkgType" [37] "printcmd" "prompt" "repos" [40] "rl_word_breaks" "scipen" "show.coef.Pvalues" [43] "show.error.messages" "show.signif.stars" "str" [46] "str.dendrogram.last" "stringsAsFactors" "texi2dvi" [49] "timeout" "ts.eps" "ts.S.compat" [52] "unzip" "useFancyQuotes" "verbose" [55] "warn" "warning.length" "width" 
Each of these variables can be changed to modify R performance. For more details on each element see the HTML help for the options() function. A practical example is given below.
Posted in R Data Objects, R Data Syntax
Leave a comment
Regular Expressions in R
In computing, a regular expression (abbreviated regexp) is a sequence of characters that forms a search pattern, mainly for use in pattern matching with strings. The patterns are often a combination of text abbreviations, metacharacters, and wild cards. Regular expressions are used for searching for objects, doing extractions, or find/replace operations. The use of regular expressions offers convenience and can have powerful impact on data or object management.
regexp Functions in R
Functions in R for regular expressions include:
Posted in R Data Syntax
Leave a comment
Factors in R
Categorical (e.g. qualitative) data are represented as factors in R. Factors display as character strings (e.g. labels), but are stored as integers (e.g. levels).
Creating Factors in R
Factors may be created by using the factor() or as.factor() function:
1 2 3 4 5 6 7 8 9 10 
# Create data object using factor() > age < factor(c(1, 1, 2, 2, 1, 3, 1, 2), labels = c("2035yrs", "3555yrs", "55+yrs")) > age [1] 2035yrs 2035yrs 3555yrs 3555yrs 2035yrs 55+yrs 2035yrs 3555yrs # Create data object using as.factor() > age < c("2035yrs", "2035yrs", "3555yrs", "3555yrs", "2035yrs", "55+yrs", "2035yrs", "3555yrs") > age < as.factor(age) > age [1] 2035yrs 2035yrs 3555yrs 3555yrs 2035yrs 55+yrs 2035yrs 3555yrs 
Note that it is not possible to assign labels to the factor levels within the function as.factor().
Another way to create factors in R is to split a data object into category groups and then call the factor() function:
Posted in R Data Objects, R Data Syntax
Leave a comment
R Data Syntax
The following pages introduce the fundamentals of R data syntax for program scripting and quantitative data analysis.
Posted in R Data Syntax
Leave a comment