Semester 2nd : https://fybbacahtmlslip.edublogs.org
Semester 4th : https://sppubbaca4thsempracticalslipsolution.wordpress.com
Semester 3rd:
DSA Slip Solutions:
https://sppusybbacapracticalslipsolution.wordpress.com/sy-bbaca-sppu-slips-solutions/
SY BBA(CA) PRACTICAL SLIP:
1. R Slip Solutions:
Slip 1:
Q-3. Write an R program to find the maximum and the minimum value of a given vector.
nums=c(10,20,4,2,90)
print("Original vector is : ")
print("maximum elements is : ")
print(max(nums))
print("minimum elements is : ")
print(min(nums))
Slip 2:
Q-3. Write an R program to sort a vector in ascending and descending order.
num2=c(12,2,3,4,56,12,2,6,7,8,90)
print("original vector is : ")
print(num2)
print("sorted vector in ascending order is : ")
print(sort(num2))
print("sorted vector in descending order is : ")
print(sort(num2,decreasing = TRUE))
Slip 3:
Q-3. Write an R program to compare two data frames to find the elements in first data frame that are not present in second order.
df1=data.frame(
item=c(12,23,34),
item1=c(65,54,43),
item2=c(90,89,78)
)
print(df1)
df2=data.frame(
item=c(12,33,34),
item1=c(55,54,43),
item2=c(90,89,88)
)
print(df2)
print("The elements is in first frame is not present in second frame is : ")
print(setdiff(df1,df2))
Slip 4:
Q-3. Write an R program to extract first 10 letters in lower case and last 10 letters in upper case and extract letters between 22nd and 24th letters in upper case.
print("First 10 letters in lowercase : ")
t=head(letters,10)
print(t)
print("First 10 letters in uppercase : ")
t=tail(LETTERS,10)
print(t)
e=tail(LETTERS[22:24])
print("22nd and 24th letters in upper case is : ")
print(e)
Slip 5:
Q-3. Write an R program to find sum, mean and product of a vector.
x=c(10,20,30)
print("Original Vector is : ")
print("sum is : ")
print(sum(x))
print("mean is : ")
print(mean(x))
print("product is : ")
print(prod(x))
Slip 6:
Q-3. Write an R program to create a simple bar plot of five Subject’s marks.
sub=c('DSA','BD','DM','SE','PHP')
marks=c(78,98,87,86,78)
print(sub)
print(marks)
barplot(marks,main="marks of 5 subject : ",
xlab="marks",ylab="sub",col = "black")
Slip 7:
Q-3. Write an R program to create a data frame which contains details of 5 employees and display details in ascending order.
df1=data.frame(
emp_code=c(5,3,4,2,1),
emp_name=c("ram","shyam","mahesh","paresh","suresh"),
emp_desi=c("bca","mca","bsc","bca","mca"),
emp_salary=c(2000,1000,3000,1000,4000)
)
print("Original data frame is : ")
print(df1)
print("details in ascending order is : ")
print(df1[order(df1$emp_code),])
Slip 8:
Q-3. Write an R program to create a data frame using two given vector and display duplicates elements and unique rows of said data frame.
x=c(1,2,3,4)
y=c(6,5,4,4)
print("original vector is :")
print(x)
print(y)
xy=data.frame(x,y)
print("data frame is : ")
print(xy)
print("duplicated value is in data frame is : ")
print(duplicated(xy))
print("unique rows is in data frame is : ")
print(unique(xy))
Slip 9:
Q-3. Write an R program to change the first levels of a factor with another level of given factor.
x=c('a','b','c','a','b')
print("original vector is : ")
print(x)
f=factor(x)
print("factor is :")
print(f)
levels(f)[1]="e"
print(f)
Slip 10:
Q-3. Write a script in R to create lists of cities and perform the following:
1) Give names to elements in the list.
2) Add an element at the end of the list.
3) Remove the last element.
4) Update the 3rd element.
list_data<-list(c("nashik","pune","mumbai"),
list("python","java","php"))
names(list_data)=c("city","lang")
print("list is : ")
print(list_data)
list_data[3]="new ele"
print(list_data)
list_data[3]=NULL
print(list_data)
list_data[3]="r pro"
print(list_data)
Slip 11:
Q-3. Write a script in R to create two vectors of different lengths and give these vectors as input to array and print addition and subtraction of those matrix.
v1=c(1,2,3,4)
v2=c(4,5,6,7,8,9)
print("vector 1 is : ")
print(v1)
print("vector 2 is : ")
print(v2)
array1=array(c(v1,v2),dim=c(3,3,2))
print(array1)
array2=array(c(v2,v1),dim=c(3,3,2))
print(array2)
m1<-array1[,,2]
m2<-array2[,,2]
r<-m1+m2
print("addition is :")
print(r)
r<-m1-m2
print("substraction is :")
print(r)
Slip 12:
Q-3. Write an R program to calculate Multiplication Table.
n=10
for(i in 1:10)
{
print(paste(n,'*',i,"=",n*i))
}
Slip 13:
Q-3. Consider the inbuilt iris dataset
1) Create a variable “y” and attach to it the output attribute of the “iris” dataset.
2) Create a bar plot to breakdown your output attribute.
3) Create a density plot matrix for each attribute by class values.
install.packages("ggplot2")
library(ggplot2)
data(iris)
dataset<-iris
x=dataset[,1:4]
y=dataset[,5]
plot(y)
scale=list(x=list(relation="free",y=list="free"))
barplot(x=x,y=y,plot="density")
Slip 14:
Q-3. Write an R program to concatenate two given factors in a single factor and display in descending order.
f1= factor(sample(LETTERS, size=6, replace=TRUE))
print(f1)
f2=factor(sample(LETTERS,size=6,replace=TRUE))
print(f2)
f=factor(c(levels(f1)[f1],levels(f2)[f2]))
print(f)
print("in descending order : ")
print(rev(f))
Slip 15:
Q-3. Write an R program to extract the five levels of factor created from random sample from the LETTERS.
f1<-factor(sample(LETTERS,size=20,replace=TRUE))
print("oroginal data is : ")
print(f1)
f=factor(c(levels(f1)[f1]))
print(f)
print("only 5 levels of factor is : ")
print(f1[1:5])
Slip 16:
Q-3. Consider the inbuilt mtcar dataset.
1) subset vector ,”mtcars[,1]”,for values greater than “15.0”.
2) subset “airquality” for “ozone” greater than “28” or “temp” greater than “70” and return the first five rows.
3) subset “airquality” for “ozone” greater than”100″. Select the columns “ozone”,”temp”,”month”,”day” only.
dim(airquality)
colnames(airquality)
subset(mtcars[,1],mtcars[,1]>15)
head(subset(airquality,Ozone > 28 | Temp > 70))
subset(airquality,Ozone > 100,select=c(Ozone,Temp,Month,Day))
Slip 17:
Q-3. Write an R program to calculate Decimal into binary of a given number.
dtb<-function(n)
{
if(n>1)
{
dtb(as.integer(n/2))
}
cat(n%%2)
}
dec=10
print("decimal is : ")
print(dec)
print("decimal to binary is :")
bin=dtb(dec)
print(bin)
Slip 18:
Q-3. Write an R program to create three vector a,b,c with 3 integers. Combine the three vector to become 3*3 matrix where each columns represents a vector. Print Content of a matrix.
a=c(1,2,3)
b=c(3,4,5)
d=c(6,7,8)
combine<-cbind(a,b,d)
print("content of matrix is : ")
print(combine)
Slip 19:
Q-3. Write an R program to draw an empty plot and an empty plot specify the axes limits of the graphic.
print("empty plot specify the axes of limit of the graphics : ")
plot(1,type="n",xlab="",ylab="",xlim=c(0,20),ylim=c(0,20))
Slip 20:
Q-3. Consider the weather dataset..
1) selecting using column number
2) selecting using column name
3) make a scatter plot to compare wind speed and temperature.
/*In this program you want to download following packages.Then after your program is run.
1.rnoaa
2.ggplot
3.devtools*/
dim(airquality)
with(airquality,plot(Ozone ~ Temp))
Slip 21:
Q-3. Consider the plantGrowth inbuilt dataset.
1) create a variable “y” and attch to it the output attribute of the “plantGrowth” dataset.
2) create a barplot to breakdown your output attribute.
3) create a density plot matrix for each attribute by class value.
/*In this program you required to install following packages ,
1.dplyr
2.ggplot
3.ggplot2
4.plantgrowth
5.caret
*/
data(PlantGrowth)
dataset<-PlantGrowth
library(caret)
x<-dataset[,1:1]
y<-dataset[ ,2]
y
library(dplyr)
library(ggplot2)
dataset %>% ggplot(aes(x=y)) + geom_bar() + labs(x = "Iris Flower Species")
scales<-list(x = list(relation = "free"), y = list(relation = "free"))
barplot(x = x, y = y, plot = "density", scales = scales)
Slip 22:
Q-3. Write an R program to print the numbers from 1 to 100 and print “SY” for multiples of 3, print “BBA” for multiples of 5, print”SYBBA” for multiples of both.
for(i in 1:100)
{
if(i%%3==0 & i%%5==0)
{
print("SYBBA")
}
else if(i%%3==0)
{
print("SY")
}
else if(i%%5==0)
{
print("BBA")
}
else
{
print(i)
}
}
Slip 23:
Q-3. Write a R script to create two vectors of different lengths and give these vectors as input to array and print second row of second matrix of the array.
a=c(1,2,3,5)
b=c(1,2,3,4,5,6,7,8,9)
print("vector 1 is : ")
print(a)
print("vector 2 is : ")
print(b)
result=array(c(a,b),dim=c(3,3,2))
print("new array is : ")
print(result)
print("second row of second matrix of an array : ")
print(result[2,,2])
Slip 24:
Q-3. Write a script in R to create two vectors of different lengths and give these vectors as input to array and print multiplication of those matrix.
v1 <- c(1, 2, 3)
v2 <- c(4, 5, 6, 7)
print("vector 1 is : ")
print(v1)
print("vector 2 is : ")
print(v2)
matrix1 <- matrix(v1, nrow = length(v1), ncol = 1)
print("matrix 1 is : ")
print(matrix1)
print("matrix 2 is : ")
print(matrix2)
matrix2 <- matrix(v2, nrow = length(v2), ncol = 1)
result_matrix <- matrix1 %*% t(matrix2)
print(result_matrix)
Slip 25:
Q-3. Write an R program to create list of elements using vectors, matrices and a functions. Print the content of a list.
l=list(c(1,2,3,4,12,7),
month.abb,
matrix(c(3,-8,1,-3),nrow=2),
asin
)
print("Content of the list")
print(l)
Slip 26:
Q-3. Write a script in R to create an array, passing in a vector of values and a vector of dimensions. Also provides names for each dimension.
a=array(6:30,
dim=c(4,3,2),
dimnames=list(
c("col1","col2","col3","col4"),
c("row1","row2","row3"),
c("part1","part2")))
print(a)
Slip 27:
Q-3. Write an R program to calculate binary into decimal of a given number.
btd <- function(b_string)
{
d_no <- 0
b_digit <-strsplit(b_string,"")[[1]]
b_digit <- as.integer(b_digit)
n<-length(b_digit)
for (i in 1:n) {
d_no <-d_no + b_digit[i]*2^(n-i)
}
return(d_no)
}
b_no <-as.character(readline(prompt = "Enter a binary : "))
print(paste(b_no,"binary to decimal is : ",btd(b_no)))
Slip 28:
Q-3. Write an R program to convert a given matrix to a list and print list in ascending order.
a=matrix(c(3,2,1,5),nrow=2,ncol=2)
print("original matrix is : ")
print(a)
l=unlist(as.list(a))
print("list of matrix in ascending order is : ")
sorting=sort(l)
print(sorting)
Slip 29:
Q-3. Write an R program to create a list of students and perform the following.
1) Give names to the students in the list
2) Add student at the end of the list.
3) Remove the first student in the list.
4) Update the second last elements.
a=list("deep","gaurav","harshal","sameer")
print("original list is ")
print(a)
names(a)<-c("a","b","c","d")
print("names of list : ")
print(a)
a[5]="santosh"
print(a)
a[1]=NULL
print(a)
a[2]="chirag"
print(a)
Slip 30:
Q-3. Write an R program to sort a list of 10 strings in ascending order and descending order.
a<-c("deep","gaurav","sameer","harshal","chirag","santosh","prasad","mohit","harshil","rajesh")
list_str=list(a)
print("original string is : ")
print(list_str)
sort_str=sort(a)
print("sorting string in ascending order is : ")
print(sort_str)
sort_str=sort(a,decreasing=TRUE)
print("sorting string im desceding order is : ")
print(sort_str)