R-Programming - Ai&ds 10 Prog
R-Programming - Ai&ds 10 Prog
Introduction to Non-Tabular Data Types: Time series, spatial data, Network data. Data
Transformations: Converting Numeric Variables into Factors, Date Operations, String Parsing.
DATA TRANSFORMATIONS:
FUNCTIONS REQUIRED:
c():
The c() function is used to concatenate or combine values into a single vector. It stands for
"combine" or "concatenate". In the provided code, it's used to create a numeric vector by combining
individual numeric values.
as.factor():
The as.factor() function is used to convert a vector into a factor. Factors in R are used to represent
categorical data. The function assigns a numeric code to each unique value in the vector and stores
these codes as integers. It's useful when you want to work with categorical data in R.
cat():
The cat() function is used to concatenate and print values to the console. It stands for "concatenate
and print". It is typically used for simple concatenation and printing without any formatting. In the
provided code, it's used to print messages to the console.
print():
The print() function is used to print the specified object to the console or to a file. It's a generic
function in R used for printing various types of R objects. In the provided code, it's used to print the
original numeric vector and the converted factor vector to the console.
SOURCE CODE:
OUTPUT:
Date Operations:
AIM:To Write an R program for Date Operations.
FUNCTIONS REQUIRED:
c():
The c() function is used to concatenate or combine values into a single vector. It stands for
"combine" or "concatenate". In the provided code, it's used to create a numeric vector by combining
individual numeric values.
Sys.Date():
The Sys.Date() function is used to obtain the current system date in R. It returns a Date object
representing the current date.
print():
The print() function is a generic function in R used to print its argument. It is used to display the
output on the console. When applied to a Date object, it prints the date in a human-readable
format.
format():
The format() function is used to format dates and times in R. It takes a Date object as input and
converts it into a character string according to the specified format. Commonly used format codes
include %Y for year, %m for month, %d for day, etc.
as.Date():
The as.Date() function is used to convert character data into Date objects in R. It is often used to
convert strings representing dates into Date objects so that date arithmetic and other operations
can be performed on them.
SOURCE CODE:
OUTPUT:
Today's date:
[1] "2024-04-16"
Date operations:
Yesterday's date: 2024-04-15
Tomorrow's date: 2024-04-17
FUNCTIONS REQUIRED:
c():
The c() function is used to concatenate or combine values into a single vector. It stands for
"combine" or "concatenate". In the provided code, it's used to create a numeric vector by combining
individual numeric values.
print():
The print() function is a generic function in R used to print its argument. It is used to display the
output on the console. When applied to a Date object, it prints the date in a human-readable
format.
strsplit():
The strsplit() function is used to split a character vector (or a string) into substrings based on a
specified delimiter or regular expression pattern.
It takes two main arguments: the character vector or string to split, and the delimiter or regular
expression pattern used for splitting.
The function returns a list where each element contains the substrings resulting from the split
operation.
grep():
The grep() function is used to search for matches of a specified pattern within a character vector or
string.
It takes several arguments, including the pattern to search for, the character vector or string to
search within, and optional parameters controlling the matching process.
When value = TRUE is specified, grep() returns the actual elements of the character vector that
match the pattern, rather than their indices.
If value = FALSE (the default), grep() returns the indices of matching elements within the vector.
SOURCE CODE:
# Sample string
text<- "The quick brown fox jumps over the lazy dog."
OUTPUT: