R Programming
R Programming
Q.3 The following table shows the number of units of different products
sold on different days:
Create five sample numeric vectors from this data
Product <- c("Bread","Milk","Cola Cans","Chocolate Bars","Detergent")
Monday <- c(12,21,10,6,5)
Tuesday <- c(3,27,1,7,8)
Wednesday <- c(5,18,33,4,12)
Thursday <- c(11,20,6,13,20)
Friday <- c(9,15,12,12,23)
t <- cbind(t1,t2,t3,t4)
tp <- paste(t1,t2,t3,t4, sep=" ")
print(tp)
Q.5 Which function is used to construct a vector in R. Write a script to
generate the following list of numerical values with spaces: 3 5 6 9 11
34
num_vec <- c(3,5,6,9,11,34)
print(num_vec)
# Extract 3rd and 5th row with 2nd and 4th column.
result2 <- df[c(3,5),c(2,4)]
print(result2)
print(df1)
Q.8 Suppose you have two datasets A and B. Dataset A has the
following data: 1 2 4 5. Dataset B has the following data: 6 7 8 9.
Which function is used to combine the data from both datasets into
dataset C. Demonstrate the function with the input values and write
the output.
a1 <- c(1,2,4,5)
a <- data.frame(a1)
b1 <- c(6,7,8,9)
b <- data.frame(b1)
c <- merge(a, b)
c <- rbind(a, b)
print(c)
c <- rbind(a, b)
print(c)
A bar chart represents data in rectangular bars with length of the bar
proportional to the value of the variable. R uses the function barplot()
to create bar charts.
CODE
Monday <- c(12,21,10,6,5)
barplot(Monday)
Boxplots are a measure of how well distributed is the data in a data
set. It divides the data set into three quartiles. This graph represents
the minimum, maximum, median, first quartile and third quartile in
the data set. It is also useful in comparing the distribution of data
across data sets by drawing boxplots for each of them.
#BoxPlot
boxplot(Monday ~ Tuesday, data = df1, NOTCH = TRUE)