Q:

Write a R program to convert a given list to vector

0

Write a R program to convert a given list to vector.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now