Write a R program to add 3 to each element in a given vector. Print the original and new vector.
v = c(1, 2, NULL, 3, 4, NULL) print("Original vector:") print(v) new_v = (v+3)[(!is.na(v)) & v > 0] print("New vector:") print(new_v)
Sample Output:
[1] "Original vector:" [1] 1 2 3 4 [1] "New vector:" [1] 4 5 6 7
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer