
Word Cloud Links
Animation (3) CSP (2) Data (22) Data Science (3) Distributions (1) Dust (7) Economics (14) Engineering (9) Equipment Venders (1) Faster R (1) GDAL (5) Germany (1) ggplot2 (19) GIS (5) Irradiance (17) Kuwait (1) LaTeX (11) Linux (2) Meteorology (16) Misc Tricks (3) Modeling (6) Natural Gas (2) Nuclear (1) O&M (2) Projects (5) Project Valuations (6) Qatar RE (13) R Colors (9) R Data Import (6) R Data Objects (16) R Data Syntax (6) Renewable Energy (14) RE Policy (7) Resource Assessment (19) R Graphics (19) R Packages (3) R Programming (20) Saudi Arabia (2) Scientific Computing (1) Solar (35) Spatial Analysis (6) Storage (1) UAE (3) Ubuntu (1) Website (2) WECC (2) Wind (5)Rbloggers
Renewable Energy World
Archives
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 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
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
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
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