# Z-SCORES , Screen 8

I did not understand anything about the code & the O/P on the screen

1. How index 1 & index 2 are calculated in mutate() & how replace() code works here.

2. In the tibble , are we taking only 6 houses for calculation & why there is NA in all the rows.

Kindly elaborate.

Hello @sharathnandalike

Sorry for that. Let’s try to remedy this problem!

We are trying to create a column that contains this calculation `SalePrice/ 100000 + 37` for even indices and this calculation `SalePrice/ 100000 + 37` for odd indices.

To do this, we created two new columns (`index_1` and `index_2`) from the `SalePrice` column so that:

• The first column, `index_1`, will contain this calculation `SalePrice/ 100000 + 37` for the even indices and NA for the odd indices.
• The second column, `index_2`, will contain this calculation `SalePrice/ 90000 - 2.8` for odd indices and NA for the even indices.

This also explains why all the rows have NA • The function `mutate()` allows you to create a new column.
• The function `row_number()` yields the index of each row in the `houses` dataframe.
• The function `replace()` allows you to replace values in a vector if a condition is met. Here is the syntax:
``````replace(vector, condition_for_replacement, replacement_value)
``````

So, this line `mutate(index_1 = replace(index_1, row_number() %% 2 != 0, NA_real_) )` means:
if the index is odd (i.e., `row_number() %% 2 != 0`) replace the existing value in the column `index_1` (previously created with this line `mutate(index_1 = SalePrice/ 100000 + 37)` by NA of type double (i.e.
`NA_real_`).

If you wonder why `NA_real_` and not `NA`. the reason is that the `replace()` function works on vectors and a vector can only contain one type of value (integer, real, string, logical, …). Hence, we have to specify what is the right `NA`.

This is a typo; we have to specify here that we are only showing the head of the `houses` dataframe. The response of the NAs is above.

Thank you for all these interesting questions. Might I suggest you planning to do the other courses in our R path where we have discussed most of these aspects? That said, this is just a future suggestion, I will always be happy to answer your questions which contribute to detect pain points in our content.

Best regards,
John.

Hello John,

Which course in R path I have missed. I am interested in only Data Analysis ( not data engineering - data cleaning , SQL ,etc ) which I think I have chosen all the relevant missions.

FYI .
Only Thing is I do not know coding; I am seeing CODING FOR THE FIRST time.
This is the reason I have joined the course. I am a non-IT Engineer . I had studied Engg. more than 2 decades ago.
Hope you will help me ( as you always are) get good in R coding.

Thanks,

Sharath

1 Like

Hello @sharathnandalike

I had mainly the first step in mind (Introduction to Programming in R, Intermediate R Programming). But I saw that you put some comments about the first course, so I guess you’re already doing them I’m delighted to know this. I will do my best to make this first experience as enjoyable as possible.

Absolutely yes!

Best regards,
John.