Create the following matrix “mat” in R 1.0 0.5 0.1 0.1 0.1 1.0 0.1 0.1 0.1 0.1 1
ID: 3851253 • Letter: C
Question
Create the following matrix “mat” in R
1.0
0.5
0.1
0.1
0.1
1.0
0.1
0.1
0.1
0.1
1.0
0.1
0.1
0.1
0.1
1.0
Rename rows to R1, R2, R3, and R4.
Change the element at row 2 and column 4 to missing value.
Read in worms.txt as a R data set.
What object is it?
Write code to find out what the variable names are.
How many rows and columns in “Worms”?
What is the mean of “Area”?
How many “Meadow” in “Vegetation”?
Toss a six-sided die twice. The sample space consists of all ordered pairs (i; j)
of the numbers 1; 2; … ; 6, that is, S = f(1; 1); (1; 2); … ; (6; 6)g. We know the size of sample space is 36. Let A = outcomes matching and B = sum of outcomes at least 8. Using R to find P(A|B) and P(B|A).
1.0
0.5
0.1
0.1
0.1
1.0
0.1
0.1
0.1
0.1
1.0
0.1
0.1
0.1
0.1
1.0
Explanation / Answer
For cleating the matrix use thia comand:
mat <- matrix( c(1.0,0.5,.1,0.1,0.1,1.0,0.1,0.1,0.1,0.1,1.0,0.1,0.1,0.1,0.1,1.0), nrow = 4, byrow=TRUE)
Rename rows to R1, R2, R3, and R4. as follow
rownames = c("R1", "R2", "R3", "R4")
mat <- matrix( c(1.0,0.5,.1,0.1,0.1,1.0,0.1,0.1,0.1,0.1,1.0,0.1,0.1,0.1,0.1,1.0), nrow = 4, byrow=TRUE,dimnames = list(rownames))
Change the element at row 2 and column 4 to missing value.:
mat["R2",4]=NA
Read in worms.txt as a R data set.
Suppose you want to read in variable "M" the give the comand
where sep=" " specify how the data was separted in file "worms.txt"
For your problem use the above said comand to read data from "worms.txt" in variable "M"
What object is it?
In R everything is an object. It totaly depend how you have read the file "worms.txt" in R. In abovle solution it is a "data frames" is a "tabular data object"
Write code to find out what the variable names are.:
M[1,]
output:
V1 V2 V3 V4 V5 V6 V7
1 Field.Name Area Slope Vegetation Soil.pH Damp Worm.density
How many rows and columns in “Worms”?:
For number of columns
ncol(M)
output:7 for above example
For number of rows:
nrow(m)
output:21
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.