Question

In: Computer Science

R-Studio (R Programming Language) 1. How would you create a vector `V` containing the values 0,...

R-Studio (R Programming Language)

1. How would you create a vector `V` containing the values 0, 0.25, 0.5, 0.75, and 1?
  
```{r}
#insert your code
```


2. Name the elements of `V`: first, second, middle, fourth, last. Describe two ways of naming elements in `V`

```{r}
#insert your code
```

3. Suppose you keep track of your mileage each time you fill up. At your last 6 fill-ups the mileage was
65311 65624 65908 66219 66499 66821 67145 67447. Enter these numbers into R as vector `miles`. Use the function `diff` on the data `miles`. What does it give? Use `sum` on the computed differences to find the total travelled distance.

```{r}
#insert your code
```

Solutions

Expert Solution

In case of any query, do comment. Please rate answer. Thanks .

Code is as below:

#R version 3.3.2

#create a vector `V` containing the values 0, 0.25, 0.5, 0.75, and 1

V <- c(0, 0.25, 0.5, 0.75, 1)

#first way to name elements

names(V) <- c("first","second","middle", "fourth","last")

#another way to name element is using setnames method as below

V <- setNames(1:5, c("first","second","middle", "fourth","last"))

#Below line is used to verify the output, you can remove it

V

#create a vector miles using difference mileage readings

miles <- c(65311, 65624, 65908, 66219, 66499, 66821, 67145, 67447)

#diff gives the difference between the element in vector mileage2-mileage1, mileage3-mileage2,

#mileage4-mileage3, mileage5-mileage4, mileage6-mileage5, mileage7-mileage6

print("difference in miles: ")

diff(miles)

#to calculate the sum of total traveled distance

print("Total traveled distance :")

sum(diff(miles))

================screen shot of the code================

Output:

Output after using second way of naming the element using setNames

Output after doing diff on Miles and then sum for getting total traveled distance:


Related Solutions

R programming language A) Create a function that accepts two arguments, an integer and a vector...
R programming language A) Create a function that accepts two arguments, an integer and a vector of integers. It returns the count of the number of occurrences of the integer in the input vector. 1]Input: num_count <-function ??? 2]Input: num_count(2,c(1,1,2,2,3,3)) 2] Output: 2 3] Input: num_count(1,c(1,1,2,2,3,1,4,5,5,2,2,1,3)) 3] Output : 4 B) Create a function that accepts 3 integer values and returns their sum. However, if an integer value is evenly divisible by 3, then it does not count towards the...
Data Structures for R studio Create a numeric vector containing 10 random numbers ranging from 1...
Data Structures for R studio Create a numeric vector containing 10 random numbers ranging from 1 to 10000. Validate that the object you created is a vector Give an example of where you might find this in a biologicall data set. Create a 10-member list containg both numeric and character data. Validate that the object you created is a list Give an example of where you might find this in a biologicall data set. Create a data frame that relates...
R Programming: create a vector for 1 to 31 and count the number of even and...
R Programming: create a vector for 1 to 31 and count the number of even and odds using ifelse()
R-Studio (R Programming Language) 4. Let the data x be given by `x <- c(1, 8,...
R-Studio (R Programming Language) 4. Let the data x be given by `x <- c(1, 8, 2, 6, 3, 8, 5, 5, 5, 5)` Use R to compute the following functions. Note, we use X1 to denote the first element of x (which is 1) etc.    1. `(X1 + X2 + . . .+ X10)/10` (use sum)    2. Find log10(Xi) for each i. (Use the log function which by default is base e) 3. Find `(Xi - 4.4)/2.875`...
Use R code Create a vector V with 8 elements (7,2,1,0,3,-1,-3,4): Transform that vector into a...
Use R code Create a vector V with 8 elements (7,2,1,0,3,-1,-3,4): Transform that vector into a rectangular matrix A of dimensions 4X2 (4- rows, 2-columns); Create a matrix transpose to the above matrix A. Call that matrix AT; Calculate matrix products: A*AT and AT*A. Present the results. What are the dimensions of those two product matrices; Square matrixes sometimes have an inverse matrix. Try calculating inverse matrices (or matrixes, if you prefer) of above matrices (matrixes) A*AT and AT*A; Extend...
R Studio Coding Exercise Problem-Set Questions 1-6 # 1) Create the following vector in 1 line...
R Studio Coding Exercise Problem-Set Questions 1-6 # 1) Create the following vector in 1 line of code without using the c() function: # [i] 4 12 20 4 12 20 4 12 # 2) Create a vector of 25 random heights between 54 and 78 inches. Cycle through the vector using a For loop and create a new vector that places each height into a category. People less than 5 feet should be categorized as short, those taller than...
This is R language Create a vector that contains the message part of each log entry...
This is R language Create a vector that contains the message part of each log entry in logsin uppercase letters. In your solution, you might want to use the function toupper(). Simply print this vector to the console. # Return vector with uppercase version of message elements in log entries # Apply extract_caps function on logs
Hey anyone good with R studio? How do you create a square shape with R code...
Hey anyone good with R studio? How do you create a square shape with R code by using plot() and lines() please show your code !
1. Let V and W be vector spaces over R. a) Show that if T: V...
1. Let V and W be vector spaces over R. a) Show that if T: V → W and S : V → W are both linear transformations, then the map S + T : V → W given by (S + T)(v) = S(v) + T(v) is also a linear transformation. b) Show that if R: V → W is a linear transformation and λ ∈ R, then the map λR: V → W is given by (λR)(v) =...
How to shorten this "if-else" statements in R studio? Thank you sooo much! fizzbuzz = function(v...
How to shorten this "if-else" statements in R studio? Thank you sooo much! fizzbuzz = function(v = NULL){ for (term in v){ if (is.infinite(term) != TRUE){ if (is.numeric(term)){ if (term == as.integer(term)){ if (term %% 3 == 0){ if (term %% 5 == 0){ print("FizzBuzz")} else { print("Fizz") } } else if (term %% 5 == 0){ print("Buzz") } else { print(term) } } else { print ("This number is not an integer.") } } else { print ("This is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT