0% found this document useful (0 votes)
2 views4 pages

4230025

Uploaded by

vmusale908
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

4230025

Uploaded by

vmusale908
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

#introduction to R software

#Assignment 1 - sem I
#Q. 1
marks=c(36,20,18,21,30,20,19,27,21,19,20,24,19,23,21);marks

#OUTPUT
marks=c(36,20,18,21,30,20,19,27,21,19,20,24,19,23,21);marks
[1] 36 20 18 21 30 20 19 27 21 19 20 24 19 23 21

#Q. 2
seq(1,37,by=3)

#OUTPUT
seq(1,37,by=3)
[1] 1 4 7 10 13 16 19 22 25 28 31 34 37

#Q. 3
rep(12,10)

#OUTPUT
rep(12,10)
[1] 12 12 12 12 12 12 12 12 12 12

#Q. 4
x=c(1,5,4);x
y=c(3,7,9,1);y
x=c(x,y);x
y=c(y,4,3,12);y
z=c(x,y);z

#OUTPUT
x=c(x,y);x
[1] 1 5 4 3 7 9 1
y=c(y,4,3,12);y
[1] 3 7 9 1 4 3 12
z=c(x,y);z
[1] 1 5 4 3 7 9 1 3 7 9 1 4 3 12

#Q.5
x=c(1,5,2,3,7,8,6);x
y=(x*x);y
z=(1/x);x
w=log10(10*x);w

#OUTPUT
> x=c(1,5,2,3,7,8,6);x
[1] 1 5 2 3 7 8 6
> y=(x*x);y
[1] 1 25 4 9 49 64 36
> z=(1/x);x
[1] 1 5 2 3 7 8 6
> w=log10(10*x);w
[1] 1.000000 1.698970 1.301030 1.477121 1.845098 1.903090 1.778151

#Q.6
age=c(22,27,31,41,30,25,19,20,23,35);age
age[4]
age30=age[age>30];age30
length(age)
age[c(8,9,10)];age
age[c(5,7)];age
age2=age[age>20&age<25];age2

#OUTPUT
age=c(22,27,31,41,30,25,19,20,23,35);age
[1] 22 27 31 41 30 25 19 20 23 35
> age[4]
[1] 41
> age30=age[age>30];age30
[1] 31 41 35
> length(age)
[1] 10
> age[c(8,9,10)];age
[1] 20 23 35
[1] 22 27 31 41 30 25 19 20 23 35
> age[c(5,7)];age
[1] 30 19
[1] 22 27 31 41 30 25 19 20 23 35
> age2=age[age>20&age<25];age2
[1] 22 23

#Q.7
Height=c(140,137,150,147,139,140,150,132,138,140);Height
Weight=c(55,57,59,62,61,60,60,58,59,57);Weight
d1=data.frame(Height=Height,Weight=Weight);d1
bh=Height[Height>145];bh
bw=Weight[Weight>55];bw
bhw=subset(d1,Height>140&Weight>60);bhw

#Q.8

#OUTPUT
Height=c(140,137,150,147,139,140,150,132,138,140);Height
[1] 140 137 150 147 139 140 150 132 138 140
> Weight=c(55,57,59,62,61,60,60,58,59,57);Weight
[1] 55 57 59 62 61 60 60 58 59 57
> d1=data.frame(Height=Height,Weight=Weight);d1
Height Weight
1 140 55
2 137 57
3 150 59
4 147 62
5 139 61
6 140 60
7 150 60
8 132 58
9 138 59
10 140 57
> bh=Height[Height>145];bh
[1] 150 147 150
> bw=Weight[Weight>55];bw
[1] 57 59 62 61 60 60 58 59 57
> bhw=subset(d1,Height>140&Weight>60);bhw
Height Weight
4 147 62

#Q.8
Price=c(10,15,20,42,50,60);Price
Quantity=c(4,20,15,10,16,8);Quantity
d1=data.frame(Price=Price,Quantity=Quantity);d1
v=Price*Quantity;v
d1=(transform(d1,"v"=v));d1

#OUTPUT
Price=c(10,15,20,42,50,60);Price
[1] 10 15 20 42 50 60
> Quantity=c(4,20,15,10,16,8);Quantity
[1] 4 20 15 10 16 8
> d1=data.frame(Price=Price,Quantity=Quantity);d1
Price Quantity
1 10 4
2 15 20
3 20 15
4 42 10
5 50 16
6 60 8
> v=Price*Quantity;v
[1] 40 300 300 420 800 480
> d1=(transform(d1,"v"=v));d1
Price Quantity v
1 10 4 40
2 15 20 300
3 20 15 300
4 42 10 420
5 50 16 800
6 60 8 480

#Q. 9
d1=c("vaibhav","baburao","raj","ram","raju","kaju","shyam","sanket","priyansh","rah
ul");d1
d2=c("biology","computer science","zoology","botony","geography","math","history","
art","science","bba");d2
d3=c(10000,25000,26000,29000,17000,19000,23000,11000,18000,12000);d3
d4=data.frame("name"=d1,"department"=d2,"net-salary"=d3) ;d4
d5=subset(d4,d3>20000 & d3<50000) ;d5

#OUTPUT
d1=c("vaibhav","baburao","raj","ram","raju","kaju","shyam","sanket","priyansh","rah
ul");d1
[1] "vaibhav" "baburao" "raj" "ram" "raju" "kaju" "shyam"
[8] "sanket" "priyansh" "rahul"
> d2=c("biology","computer
science","zoology","botony","geography","math","history","
+ art","science","bba");d2
[1] "biology" "computer science" "zoology" "botony"
[5] "geography" "math" "history" "\n art"
[9] "science" "bba"
> d3=c(10000,25000,26000,29000,17000,19000,23000,11000,18000,12000);d3
[1] 10000 25000 26000 29000 17000 19000 23000 11000 18000 12000
> d4=data.frame("name"=d1,"department"=d2,"net-salary"=d3) ;d4
name department net.salary
1 vaibhav biology 10000
2 baburao computer science 25000
3 raj zoology 26000
4 ram botony 29000
5 raju geography 17000
6 kaju math 19000
7 shyam history 23000
8 sanket \n art 11000
9 priyansh science 18000
10 rahul bba 12000
> d5=subset(d4,d3>20000 & d3<50000) ;d5
name department net.salary
2 baburao computer science 25000
3 raj zoology 26000
4 ram botony 29000
7 shyam history 23000

You might also like