0

I`m using

assign( paste("ship", b, sep = ""),c())

as a vector where i want to save the coordinates of certain elements of a matrix.

Now i want to use the vector, as a example the first vector it´s named ship1 and i want to add elements to that vector but I can`t use append and paste("ship", b, sep = "") because I get this error

Error in paste("barco", b, sep = "") <- append(paste("barco", b, sep = ""),  : 
target of assignment expands to non-language object

My question is: How can I use my vector without using specifically ship1 thus been able to use a generic method to fill all other "ship b" vectors

TeBA
  • 1
  • Please take a look at [Why is using assign bad?](https://stackoverflow.com/questions/17559390/why-is-using-assign-bad) and then edit your question to provide a [reproducible code example including sample data](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Maurits Evers Nov 03 '18 at 13:16

1 Answers1

1

You need get.

b = 1
VName = paste("ship", b, sep = "")
assign(VName,c())
assign(VName, append(get(VName), 1:3))
get(VName)
[1] 1 2 3

But see @MauritsEvers comment about using assign

G5W
  • 36,531
  • 10
  • 47
  • 80
  • You might want to use paste0() since it is a bit faster. – Elin Nov 03 '18 at 14:17
  • thanks for the help but i don´t think I get it right. My problem is that i don´t know hot to use a generic form to use the vector that I want based only in the b of it´s name – TeBA Nov 03 '18 at 15:25