R PROGRAMMING
R PROGRAMMING
SECTION- A
I Answer any SIX of the following: (6 x 2=12)
1.What is R-Programming? Who developed R?
R is a free open source programming language for statistical computing and
data visualization is called R programming.
Ross Ihaka and Robert Gentle man was developed R.
2.List any two differences between vector and list.
Vector:
1. Vector contains elements of the same data type, such as numeric,
character, or logical.
2. Vector is created using c() function.
List:
1.List is a collection of elements of different types such as number, vector,
matrix etc.
2.List is created using list() function.
3.Explain NA and NAN with example.
NA stands for Not available. NA are used to represent missing values.
Example: x<-c(4,5,6,NA,6,8,NA)
Print(x)
NAN stands for Not a Number and applies to numerical values as well as real
imaginary parts of the complex values but not to values of integer vector.
NAN usually appears when you divide zero by zero, find log of negative
numbers.
Example 1: x<-0
Y<-0
Print(x/y)
Example 2: x= -5
Print(log (x))
4.Explain timings in R.
Sys.time():- This function returns the current time in R. Sys.time() is used to
find the duration of the R code or function.
Sys.sleep():-Sys.sleep Suspends the execution of R expression for specified
time interval of a n seconds.
System.time():-This function helps to measure the execution time of code
expression compared to Sys.time() the system.time() returns three
information the user, system and elapsed time.
5.Find mean, median and mode for the following:
12, 10, 9, 11, 7, 11, 8, 13, 6.
SECTION- B
Example:
numbers
divide_numbers <- function(num1, num2) {
tryCatch(
expr = {
result <- num1 / num2
print(paste("The result is:", result))
},
error = function(e) {
print(paste("An error occurred:", e$message))
},
warning = function(w) {
print(paste("A warning occurred:", w$message))
}
)
}
12.What is function? Write a R code to find the factorial of a number using
Recursion.
Function is a block of code which only runs when it is calles.
>Factorial<-function(n)
{
If(n==0)
Return(1)
Else
Return(n*factorial(n-1))
}
N=as.integer(readline(prompt=”Enter a number:”))
Factorial(N)
SECTION- C
1.One way ANOVA:- In one way anova there is one factor or independent
variable and compares three or more levels.
One way anova assumes that the varience within each group or roughfly equal
this is known as homogeneity of varience assumption.
Formula:-Anova=varience between/varience within is greater than 1
Anova is greater than one reject the null hypothesis
Anova is less than one accept the null hypothesis.
R provides a wide range of options for customizing plots to suit your specific
needs. Here are some ways to customize plots in R:
Example:
plot(x, y)
title("My Plot")
xlab("X Axis")
ylab("Y Axis")
2. Changing Colors:
Use the col argument to change the color of the plot.
Example:
3. Adding Legends:
Use the legend() function to add a legend to your plot.
Example:
plot(x, y)
legend("topright", c("Line 1", "Line 2"), lty = c(1, 2), col = c("red", "blue"))
4. Customizing Axis:
Use the axis() function to customize the axis.
Example:
plot(x, y)
axis(1, at = c(0, 10, 20), labels = c("0", "10", "20"))
Example:
plot(x, y)
grid()
Example:
7. Customizing Fonts:
Use the font argument to customize the font.
Example:
8. Adding Text:
Use the text() function to add text to your plot.
Example:
plot(x, y)
text(10, 10, "Hello World")
Example:
plot(x, y)
dev.copy(png, "myplot.png")
dev.off()
These are just a few examples of the many ways you can customize plots in R.
By using these options, you can create high-quality plots that effectively
communicate your data insights.
(b) 3D scatter plots are a type of plot that displays the relationship between
three variables in a three-dimensional space. They are useful for visualizing
complex relationships between variables and can be used to identify patterns,
trends, and correlations.