r programming built in functions
r programming built in functions
computations, data manipulation, statistical analysis, and more. Here are some commonly used
categories of built-in functions in R:
1. Mathematical Functions
2. Statistical Functions
• Probability Distributions:
3. Character Functions
8. Utility Functions
Example Usage:
Copy code
# Statistical functions
x <- c(1, 2, 3, 4, 5)
mean(x) #3
sd(x) # 1.581139
# String functions
# Apply function
You said:
ChatGPT said:
ChatGPT
Here’s a detailed explanation of R's built-in functions with examples, categorized to cover their usage
comprehensively for a 20-mark answer:
1. Mathematical Functions
Examples:
Copy code
x <- -16
abs(x) # 16
sqrt(16) #4
ceiling(num) # 8
floor(num) # 7
2. Statistical Functions
Examples:
r
Copy code
mean(data) # 20.4
median(data) # 20
sd(data) # 7.483314
# Summary of data
summary(data)
# 12 15 20 20.4 25 30
3. Character Functions
Examples:
Copy code
# String length
nchar(text) # 13
Examples:
r
Copy code
sort(nums) # 2, 5, 8, 9
rank(nums) # 3, 1, 4, 2
# Combining data
Examples:
Copy code
# Logical checks
# Which function
Examples:
Copy code
matrix_data <- matrix(1:9, nrow = 3)
Examples:
Copy code
# Normal distribution
Examples:
Copy code
Sys.Date() # "2024-12-01"
# Date arithmetic
9. Input/Output Functions
These functions help in reading and writing data files.
Examples:
Copy code
write.csv(data, "data.csv")
print(read_data)
Examples:
Copy code
x <- c(1, 2, 3)
is.numeric(x) # TRUE
y <- as.character(x)
is.character(y) # TRUE
# Length of a vector
length(x) #3
Comprehensive Example
Copy code
# Statistical summary
mean(data) # 7.1
# Logical operation
# String operation
toupper(text) # "ANALYSIS"
This detailed explanation and examples showcase the versatility of R’s built-in functions, making
them invaluable for diverse data analysis tasks.