The weighted mean & Median , Screen 6 , 2nd question

In regard to the code below, if a vector contains a mix of strings & numbers , is the vector considered as having all string values.

as.numeric(stringr::str_replace(rooms, ‘10 or more’, ‘10’))

1 Like

Hello @sharathnandalike

This is a very good question.

No. If you try to add number (without quotes) like in this syntax stringr::str_replace(rooms, '10 or more', 10), you will get this kind of error:

Error : `replacement` must be a character vector


This is not possible in R. A vector is supposed to contain values of the same type.