Write a R program to convert a given list to vector.
n1 = list(1,2,3) c1 = list(4,5,6) print("Original lists:") print(n1) print(c1) print("Convert the lists to vectors:") v1 = unlist(n1) v2 = unlist(c1) print(v1) print(v2) print("Add two vectors:") v = v1 + v2 print("New vector:") print(v)
Sample Output:
[1] "Original lists:" [[1]] [1] 1 [[2]] [1] 2 [[3]] [1] 3 [[1]] [1] 4 [[2]] [1] 5 [[3]] [1] 6 [1] "Convert the lists to vectors:" [1] 1 2 3 [1] 4 5 6 [1] "Add two vectors:" [1] "New vector:" [1] 5 7 9
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