0% found this document useful (0 votes)
3 views

Lovesh Gamma R Assignment

Fdd

Uploaded by

gargarpan288
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Lovesh Gamma R Assignment

Fdd

Uploaded by

gargarpan288
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

num <- 100.

print(typeof(num)) # Output: "double"

text <- "Revenue"

print(typeof(text)) # Output: "character"

# Example of is.numeric()

revenue <- 150000

is_revenue_numeric <- is.numeric(revenue)

print(is_revenue_numeric) # Output: TRUE

is.numeric(100.5) # Output: TRUE

is.numeric("Profit") # Output: FALSE

# Example of is.integer()

number_of_employees <- 150L

is_employee_count_integer <- is.integer(number_of_employees)

print(is_employee_count_integer) # Output: TRUE

is.integer(10L) # Output: TRUE

is.integer(10) # Output: FALSE

# Example of is.character()

employee_name <- "John Doe"

is_name_character <- is.character(employee_name)

print(is_name_character) # Output: TRUE

is.character("Revenue") # Output: TRUE

is.character(100) # Output: FALSE

# Example of is.logical()

is_manager <- TRUE

is_manager_logical <- is.logical(is_manager)

print(is_manager_logical) # Output: TRUE

is.logical(TRUE) # Output: TRUE


is.logical(0) # Output: FALSE

# Example of is.factor()

department <- factor(c("HR", "Finance", "IT"))

is_department_factor <- is.factor(department)

print(is_department_factor) # Output: TRUE

factor_data <- factor(c("High", "Medium", "Low"))

is.factor(factor_data) # Output: TRUE

library(lubridate)

# Example of is.Date() and is.POSIXct()

project_start_date <- as.Date("2024-01-01")

is_project_start_date <- is.Date(project_start_date)

print(is_project_start_date) # Output: TRUE

project_end_datetime <- as.POSIXct("2024-12-31 23:59:59")

is_project_end_datetime <- is.POSIXct(project_end_datetime)

print(is_project_end_datetime) # Output: TRUE

date <- as.Date("2024-08-09")

is.Date(date) # Output: TRUE

# Example of is.list()

employee_profile <- list(Name = "John Doe", Age = 35, Salary = 60000)

is_employee_profile_list <- is.list(employee_profile)

print(is_employee_profile_list) # Output: TRUE

# Example of is.data.frame()

employee_data <- data.frame(

Name = c("John", "Jane", "Paul"),


Age = c(28, 34, 29),

Department = c("HR", "Finance", "IT"),

Salary = c(50000, 60000, 55000)

is_employee_data_frame <- is.data.frame(employee_data)

print(is_employee_data_frame) # Output: TRUE

# Example of is.vector()

sales_vector <- c(1000, 1500, 2000, 2500)

is_sales_vector <- is.vector(sales_vector)

print(is_sales_vector) # Output: TRUE

# Example of is.matrix()

sales_matrix <- matrix(

c(1000, 1500, 2000, 2500, 3000, 3500),

nrow = 2,

ncol = 3

is_sales_matrix <- is.matrix(sales_matrix)

print(is_sales_matrix) # Output: TRUE

# Example of is.array()

sales_array <- array(

1:24,

dim = c(4, 3, 2)

is_sales_array <- is.array(sales_array)

print(is_sales_array) # Output: TRUE


complex_number <- 3 + 4i

is_complex_number <- is.complex(complex_number)

print(is_complex_number) # Output: TRUE

raw_data <- charToRaw("Data")

is_raw_data <- is.raw(raw_data)

print(is_raw_data) # Output: TRUE

# Numeric data type example

salary <- 50000

bonus <- 5000.50

total_compensation <- salary + bonus

print(total_compensation) # Output: 55000.5

num <- 100.5

print(class(num)) # Output: &quot;numeric&quot;

# Integer data type example

number_of_employees <- 150

number_of_departments <- 5

average_employees_per_department <- number_of_employees / number_of_departments

print(average_employees_per_department) # Output: 30

int <- 10L

print(class(int)) # Output: &quot;integer&quot;

# Factor data type example


employee_gender <- factor(c("&quot;Male&quot;, &quot;Female&quot;, &quot;Male&quot;,
&quot;Female&quot;, &quot;Male&quot;"))

levels(employee_gender)

# Output: &quot;Female&quot; &quot;Male&quot;

factor_data <- factor(c("&quot;High&quot;, &quot;Medium&quot;, &quot;Low&quot;"))

print(class(factor_data)) # Output: &quot;factor&quot;

# Complex data type example

complex_number <- 3 + 4i

print(complex_number) # Output: 3+4i

print(class(complex_number)) #Complex

# Raw data type example

raw_data <- charToRaw("&quot;Data&quot;")

print(raw_data) # Output: 44 61 74 61

print(class(raw_data)) #Raw

# List data type example

employee <- list("Name = &quot;John Doe&quot;, Age = 35, Salary = 60000, Department =
&quot;Finance&quot;")

print(employee)

print(class(employee)) # List

# Data Frame example

employee_data <- data.frame(

Name = c("&quot;John&quot;, &quot;Jane&quot;, &quot;Paul&quot;"),

Age = c(28, 34, 29),


Department = c("&quot;HR&quot;, &quot;Finance&quot;, &quot;IT&quot;"),

Salary = c(50000, 60000, 55000)

print(employee_data)

print(class(employee_data)) # DataFrame

# Numeric vector example

sales <- c(1000, 1500, 2000, 2500)

# Character vector example

departments <- c("&quot;HR&quot;, &quot;Finance&quot;, &quot;IT&quot;,


&quot;Marketing&quot;")

# Logical vector example

is_profitable <- c(TRUE, TRUE, FALSE, TRUE)

print(sales)

print(departments)

print(is_profitable)

print(class(departments))

print(class(is_profitable)) # Vector

# Numeric matrix example

sales_matrix <- matrix(

c(1000, 1500, 2000, 2500, 3000, 3500),

nrow = 2,

ncol = 3,

byrow = TRUE

# Print the matrix

print(sales_matrix)

print(class(sales_matrix))
# Example using || and |

x <- TRUE

y <- FALSE

# Using || for single element comparison

result_single <- x || y

print(result_single) # Output: TRUE

# Using | for element-wise comparison

vec1 <- c(TRUE, FALSE, TRUE)

vec2 <- c(TRUE, TRUE, FALSE)

result_vector <- vec1 | vec2

print(result_vector) # Output: TRUE TRUE TRUE

result <-(x>10) || (y==10)

print(result) # Output: TRUE

# Example using !

x <- TRUE

not_x <- !x

print(not_x) # Output: FALSE

result <- !(x == 5)

print(result) # Output: FALSE

# Example using xor()

x <- TRUE

y <- FALSE

result <- xor(x, y)


print(result) # Output: TRUE

# Example using all()

vec <- c(TRUE, TRUE, TRUE)

result <- all(vec)

print(result) # Output: TRUE

# Example using any()

vec <- c(FALSE, FALSE, TRUE)

result <- any(vec)

print(result) # Output: TRUE

# Example using identical()

x <- c(1, 2, 3)

y <- c(1, 2, 3)

z <- c(1, 2, 4)

result1 <- identical(x, y)

result2 <- identical(x, z)

print(result1) # Output: TRUE

print(result2) # Output: FALSE

# Example using is TRUE()

x <- TRUE

result <- isTRUE(x)

print(result) # Output: TRUE

# Example using which()

vec <- c(FALSE, TRUE, TRUE, FALSE)


result <- which(vec)

print(result) # Output: 2 3

output

You might also like