# R query question

HI All,

Consider "trees" dataset available in R Package 'data', clean the dataset by removing the rows having largest and next largest heights AND removing the rows having smallest and next smallest heights. From the cleaned data consider the columns Girth, Height(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. Create matrix b with column 'Volume' from cleaned data.
Find y=(A transpose A)^-1 A transpose b

It seems that you recently asked a question that originated from a class or workshop, and I wanted to make sure you were seeking help here in a way that maximizes the chances of getting good help (without violating our homework policies).

Our homework guide is here: FAQ: Homework Policy

### How should one ask a homework question?

1. Never copy-paste instructions from an assignment (even for online courses).
2. Explicitly mention the course you are taking and use the #homework tag.
3. Ask your question as a reproducible example (reprex), preferably prepared for posting using the `reprex` package.

### What's the best way to ask a specific homework-related question?

Hi,

Do you know solution for this?

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

library(tidyverse)

nrow(iris)
#150

which.min(iris\$Petal.Length)
#23
which.max(iris\$Petal.Length)
#119
iris_p1 <- slice(iris,
-23,
-115)

which.min(iris_p1\$Petal.Length)
#14
which.max(iris_p1\$Petal.Length)
#117
iris_p2<- slice(iris_p1,
-14,
-114)

#how many records of cleaned data ?
nrow(iris_p2)
#146

#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 ?

Thanks so much for the solution. I was given text from where I wrote here.

Any idea how to calculate this?

Find y=(A transpose A)^-1 A transpose b

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.