Heres how to make matrices via a similar pattern but for iris, rather than trees.
# Consider "iris" dataset in base R.
#clean the dataset by removing the rows having largest and next largest Petal Lengths
# AND removing the rows having smallest and next smallest Petal Lengths
#how many records to start with ?
iris_p1 <- slice(iris,
#how many records of cleaned data ?
#From the cleaned data consider the columns Petal.Length, Sepal length (in that order) as matrix A
#and insert a vector having 1s as the first column of this matrix A,
#i.e. all the values of the first column should have 1.
(matrix_A <- cbind(1,select(iris_p2,
Petal.Length,Sepal.Length) %>% as.matrix()))
#Create matrix b with column 'Petal width' from cleaned data.
(matrix_B <- select(iris_p2,Petal.Width) %>% as.matrix())
I wonder about whether you made errors reporting the required matrix operations ? were you given text which you are duplicating exactly, or have you transcribed that from an image ?