Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
75 views

Data Manipulation Assign.

1) The document provides three problems to solve using R. The first problem involves importing a dataset, checking and removing NA values, replacing an NA with a name, and analyzing the dataset. 2) The second problem involves creating two matrices and multiplying them. 3) The third problem involves creating two other matrices and multiplying each value by its successive position.

Uploaded by

shravan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views

Data Manipulation Assign.

1) The document provides three problems to solve using R. The first problem involves importing a dataset, checking and removing NA values, replacing an NA with a name, and analyzing the dataset. 2) The second problem involves creating two matrices and multiplying them. 3) The third problem involves creating two other matrices and multiplying each value by its successive position.

Uploaded by

shravan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Name:-- shravan kumar

Batch id:-08062021

Module – 2

Problem 1: Import the given dataset and check for ‘NA’ values in it using the appropriate
func on. Now follow the given steps to manipulate your data:
Note: - Use Data Manipula on Dataset.
a) Create a new data frame using the given data frame (i.e. the given dataset) by
removing the ‘NA’ values.
b) Consider the given dataset to replace the first NA value in the dataset with your
name in that place.
c) Find the factor of each column in the dataset
d) Find the class of each column in the dataset
e) Find the structure and summary of the dataset.
Problem 2: Use R to create the following two matrices and do the indicated matrix
mul plica on.

Problem 3: Use R to create the following two matrices and mul ply each value to its
successive posi on.

Note: Use R to solve the given problems in the above.


**********module 2************
# Problem 1: Import the given dataset and check for 'NA' values in it using the appropriate
func on. Now follow the given steps to manipulate your data:
# Note: - Use Data Manipula on Dataset.
# a) Create a new data frame using the given data frame (i.e. the given dataset) by
removing the 'NA' values.
#b) Consider the given dataset to replace the first NA value in the dataset with your
name in that place.
#c) Find the factor of each column in the dataset
#d) Find the class of each column in the dataset
#e) Find the structure and summary of the dataset.

# solu on:-
Install.package(“readr”)
library(readr)
> data1=read.csv(file.choose())
> data2=data.frame(data1)
> View(data2)
> data3=na.omit(data2)
> data3[8,2]="vishnu"
> View(data3)
> y=factor(data3$gender)
> y
[1] f m m m f f m f f m m f f m m m m m m f m f m f m f m m m m f f f f f f f m
[39] f m f f f m m f f m m f f m m m f f f m f f m m f m f m f f f m f f f m f f
[77] f m m m f m m f m m f f f m f f m f m f m f m m f f m f f f m f f f m m f m
[115] m m m m f f f m f f m m f f m m f f m m f f m f
Levels: f m
> z=factor(data3$admission_status)
> z
[1] yes no no no yes yes yes no yes
[10] unknown unknown yes yes no yes no yes no
[19] yes yes yes yes yes yes yes yes no
[28] no unknown unknown no no unknown unknown unknown unknown
[37] unknown unknown unknown no no no no unknown unknown
[46] yes yes yes yes yes yes yes yes yes
[55] no no yes no no yes no no no
[64] yes yes yes yes yes yes yes yes no
[73] no no no no unknown unknown unknown unknown unknown
[82] unknown no yes unknown no yes yes yes unknown
[91] yes unknown yes yes yes yes yes yes unknown
[100] unknown unknown no no yes no yes unknown unknown
[109] yes yes yes yes no no yes yes yes
[118] no no no unknown unknown unknown yes no unknown
[127] yes no unknown no no yes yes yes yes
[136] yes yes unknown
Levels: no unknown yes
> x=factor(data3$scores)
> x
[1] 720 640 740 690 710 660 660 700 730 700 740 650 720 700 760 710 720 690 770
[20] 720 650 710 720 710 650 690 690 750 710 730 770 690 710 710 710 740 720 710
[39] 720 710 690 700 730 690 670 710 720 740 750 710 730 730 710 690 720 690 710
[58] 720 770 720 710 740 710 740 740 730 720 760 720 740 740 710 690 710 710 730
[77] 700 750 710 710 720 680 710 710 710 740 710 710 700 690 770 770 720 730 710
[96] 720 690 690 690 750 720 670 690 710 690 750 710 680 690 730 750 700 720 680
[115] 690 700 710 730 720 720 740 680 730 680 710 740 760 710 710 710 730 680 690
[134] 720 730 750 750 720
Levels: 640 650 660 670 680 690 700 710 720 730 740 750 760 770
> s=factor(data3$index)
> s
[1] 1 2 3 4 5 6 7 9 10 11 12 13 14 15 16 17 18 19 20
[20] 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
[39] 42 44 45 46 47 48 49 50 51 53 54 55 56 57 59 60 61 62 63
[58] 64 65 66 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
[77] 84 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
[96] 104 105 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
[115] 124 125 127 128 129 130 131 132 134 135 136 137 138 139 140 141 142 143 144
[134] 145 146 147 149 150
138 Levels: 1 2 3 4 5 6 7 9 10 11 12 13 14 15 16 17 18 19 20 23 24 25 26 ... 150
> a=factor(data3$experience)
> a
[1] 21 107 57 99 208 136 70 vishnu 22 69
[11] 41 72 69 20 21 19 86 231 20 44
[21] 23 20 70 46 33 130 57 57 45 55
[31] 42 34 55 44 79 45 38 44 83 45
[41] 89 77 91 61 47 69 59 74 279 33
[51] 33 34 44 44 46 58 45 34 54 45
[61] 82 72 77 43 54 92 90 66 38 25
[71] 57 31 58 55 68 79 71 32 32 45
[81] 69 65 57 45 92 57 69 32 70 59
[91] 44 44 46 33 46 82 53 34 37 55
[101] 52 68 51 69 47 56 45 56 48 34
[111] 55 43 69 31 46 58 56 43 58 27
[121] 46 58 34 45 68 34 46 45 56 33
[131] 33 44 33 69 82 64 80 80
58 Levels: 107 130 136 19 20 208 21 22 23 231 25 27 279 31 32 33 34 37 38 ... vishnu
> class(data3$index)
[1] "integer"
> class(data3$experience)
[1] "character"
> class(data3$scores)
[1] "integer"
> class(data3$gender)
[1] "character"
> class(data3$admission_status)
[1] "character"
> str(data3)
'data.frame': 138 obs. of 5 variables:
$ index : int 1 2 3 4 5 6 7 9 10 11 ...
$ experience : chr "21" "107" "57" "99" ...
$ scores : int 720 640 740 690 710 660 660 700 730 700 ...
$ gender : chr "f" "m" "m" "m" ...
$ admission_status: chr "yes" "no" "no" "no" ...
- a r(*, "na.ac on")= 'omit' Named int [1:12] 8 21 22 43 52 58 67 85 106 126 ...
..- a r(*, "names")= chr [1:12] "8" "21" "22" "43" ...
> summary(data3)
index experience scores gender
Min. : 1.00 Length:138 Min. :640.0 Length:138
1st Qu.: 38.25 Class :character 1st Qu.:700.0 Class :character
Median : 76.50 Mode :character Median :710.0 Mode :character
Mean : 75.77 Mean :713.9
3rd Qu.:112.75 3rd Qu.:730.0
Max. :150.00 Max. :770.0
admission_status
Length:138
Class :character
Mode :character
######################################
#Problem 2: Use R to create the following two matrices and do the indicated matrix
mul plica on.
# (7,9,12,2,4,13)
#(1,7,12,19,2,8,13,20,3,9,14,21)

# solu on:-
a=matrix(c(7,9,12,2,4,13),nrow = 2,byrow = TRUE)
> a
[,1] [,2] [,3]
[1,] 7 9 12
[2,] 2 4 13
> b=matrix(c(1,7,12,19,2,8,13,20,3,9,14,21),nrow = 3,byrow = TRUE)
> b
[,1] [,2] [,3] [,4]
[1,] 1 7 12 19
[2,] 2 8 13 20
[3,] 3 9 14 21
> c=a%*%b
> c
[,1] [,2] [,3] [,4]
[1,] 61 229 369 565
[2,] 49 163 258 391
#################################
# Problem 3: Use R to create the following two matrices and mul ply each value to its
successive posi on.
> #(1,2,3,4,5,6,7,8,9)
> #(1,4,7,2,5,8,3,6,9)
> # solu on:-
> a=matrix(c(1,2,3,4,5,6,7,8,9),nrow = 3,byrow = TRUE)
> a
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 4 5 6
[3,] 7 8 9
> b=matrix(c(1,4,7,2,5,8,3,6,9),nrow = 3,byrow = TRUE)
> b
[,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
> c=a%*%b
> c
[,1] [,2] [,3]
[1,] 14 32 50
[2,] 32 77 122
[3,] 50 122 194
##################################

You might also like