Replacing an element of a vector going wrong

Hey,

I'm trying to replace the first element of the following vector with the number 1: (3,4,5,6,7).

The code I used is

replace (x,x[c(1)],1)

However, for some reason it then decides to replace the third element only, changing my vector into (3,4,1,6,7)

Any ideas what I'm doing wrong?

Thx

edit: I should add that when typing c(3) it replaces the 5th element...

replace (x,1,1)

Replace the first entry (1) with the value 1
You were telling jt to replace the 3rd entry.
You were telling it to get the value of the first entry and use that to determine the position of what to replace (3) , when in fact you intended 1.

1 Like

Thank you, your way works. :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.