R assignment 1
R assignment 1
R assignment 1
SESSION: - 2023-2025
NAME: -SHASWATI PAUL
YEAR: - 2ND
BATCH: -MCA 2C
STUDENT ID: - 231001271211
SUBJECT: - R Programming Lab
ASSIGNMENT 1
Develop R scripts to solve following problems:
1. Question 1:
'C' + 'D'
Error Message: Non-numeric argument to binary operator
How to resolve the error:
Corrected Code:
C <- "10"
D <- "20"
result <- as.numeric(C) + as.numeric(D)
print(result)
Output:
[1] 30
Question 2:
x = 5. .9; x
Error Message: Incorrect use of the .. operator.
How to resolve the error:
Corrected Code:
x <- c(5, 6, 7, 8, 9)
x
Output:
[1] 5 6 7 8 9
Question 3:
as.raw(20)
Output:
[1] 14
Question 4:
month.names
print(month.names)
o Output:
Question 5:
0xabc
Output:
[1] 2748
Question 6:
month.abb
Output:
[1] "Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep"
"Oct" "Nov" "Dec"
Question 7:
x20
o Output:
[1] 100
Question 8:
getwd()
Output:
[1] "/home/compiler"
Question 9:
setwd()
(29,59,5)
c(29, 59, 5)
o Output:
[1] 29 59 5
To modify the default prompt in R, we can use the options() function. By default, the R
prompt is set to "R>". However, it can be customized by specifying a new value for the
prompt option.
Code Example:
To identify the type of an R object, you can use the following functions:
Example:
x <- 42
Z <- 1 + 2i
print(Z) # Output: 1 + 2i
Addition:
Z1 <- 1 + 2i
Z2 <- -3 + 4i
sum_Z <- Z1 + Z2
print(sum_Z) # Output: -2 + 6i
Subtraction:
diff_Z <- Z1 - Z2
print(diff_Z) # Output: 4 - 2i
Multiplication:
product_Z <- Z1 * Z2
print(product_Z) # Output: -11 + 2i
Division:
quotient_Z <- Z1 / Z2
print(quotient_Z) # Output: -0.2 + 0.4i
Magnitude:
Argument:
1. Using setwd():
o To set the working directory to a specific path:
o setwd("/path/to/your/directory")
o To verify the current working directory:
o getwd()
3. On Windows:
o Example for setting the working directory:
o setwd("C:/Users/YourName/Document/R")
Output Example:
Output Example:
Output Example: