0

I am new in R and I am quite confused about the data structure. I am dealing with two vectors, each vector containing strings of character as below:

vector1: enter image description here

vector2: enter image description here

And in order to append these vectors, I used the append function as follows: text_append <- append(vector1, vector2)

But, once I append it, it creates two separate lists, whereas I wanted it to become just 1 list enter image description here

How can I make sure that I make 1 whole list of strings? I am compiling the strings, and making them as separate list wont help. I dont know what else to do.

Thanks for the help

I tried to use the append function

text_append <- append(vector1, vector2)

I expected it to retrieve me a single list of strings, but instead it gives me two separate lists.

3
  • 2
    If class(v1) says list you have to unlist them before concatenation. E.g. c(unlist(v1), unlist(v2)) Commented Mar 20 at 13:31
  • 1
    or unlist(c(v1,v2)) ... in any case, the problem is that your vector2 is a list (with one element), not a plain vector
    – lebatsnok
    Commented Mar 20 at 13:58
  • Thanks for the answer @lebatsnok I have somehow managed to solve my problem but I believe it was because the class(v1)and(v2) were lists.
    – pindakazen
    Commented Mar 31 at 5:32

1 Answer 1

0

When concatenating two vectors of strings just use c(vector1, vector2). If you want to make a list with the elements being made of the strings use as.list(c(vector1, vector2))

1
  • I tried the c() method but it unfortunately still creates 2 separate lists.
    – pindakazen
    Commented Mar 20 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.