Objects & Data Types In R
Objects & Data Types In R
#What are Objects in R?#
There are several basic R objects and data types that we encounter frequently in our R programming.
objects can be listed as:
- Numeric
- Integer
- Logical
- Complex
- Character
Data types can be Listed as:
- Vectors
- Lists
- Matrices
- Data Frames
- Factors
# Objects #
- Numeric
- Decimal values are called as numeric.
- If we assign decimal value to a variable, it will be of type Numeric.
- Even if we assign integer to a variable it will treat as numeric.
- ex. 3x = numeric
- Integer
- In order to declare as integer, we invoke 'as.integer'
- Numeric value can be invoked as integer.
- Logical
- A Logical value is often created via Comparison between variables.
- ex.) x>y ans: True or False (It will use when we use the control structure.)
- standard logical operations are "&" (and), "|" (or), "!" (negation)
- Complex
- A complex value is defined via pure imaginary value i.
- ex. 3 + 4i is complex
- Character
- A character object is used to represent string values in R, We convert objects into character values with the as.character() function.
- Two character values can be Concatenated with the paste Function.
- Many Functions are available that does string operations.(we have a dedicated chapter for it)
# How to handle Objects in R?#
- image
- Logical data are used in loops. If we are using "if loop", you always need to give a condition.
- So, we will discuss logical objects there.
- So, you need to keep in mind that whenever you are comparing two variable the return type will always be logical.
- now, the next part is character data type
- image
- quotes do matter a lot when you want to differentiate between numeric or int & char value.
- This was all about handling objects in R and the next topic will be the data types in R.
# Data types in R #
- There are several basic R objects & data types that we encounter frequently on our R programming.
- Data types can be listed as.
- Vectors
- Lists
- Matrices
- Data Frames
- Factors
# Vector #
- A vector is a list of main components which have same data types.
- Vector can be defined by using c() in R.
- A vector is a sequence of data elements of the same basic type.
- Members in a vector are officially called Components.
- length of vector can also be computed, combined and vector arithmetic is done member by member.
- Vector can be of integer, numeric, character or logical type.
# Vector Index #
- Values in a vector can be retrieved by declaring an index inside a single square bracket[].
for ex. c[3]
c[3:5]
- If the index is negative, it would strip the member whose position has the same absolute value as the negative index.
# Numeric Vector Index #
- A new
Comments
Post a Comment