Question
Which line of code will create a new vector called km that contains the elements from an existing vector called mi converted from miles to kilometers? In R language
Answers
GPT-4o mini
To convert a vector `mi` containing values in miles to kilometers, you can use the conversion factor (1 mile is approximately equal to 1.60934 kilometers). Here’s how you can create a new vector called `km` in R:
```R
km <- mi * 1.60934
```
This line of code multiplies each element in the `mi` vector by the conversion factor to produce the corresponding kilometers and assigns the result to a new vector called `km`.
```R
km <- mi * 1.60934
```
This line of code multiplies each element in the `mi` vector by the conversion factor to produce the corresponding kilometers and assigns the result to a new vector called `km`.