I have a tibble in R studio that looks like this And I need to add a column that gives to each name the same unique number. So it should look like this
I have already tried things like the below code:
people >%>
gorup_by(Name) >%>
mutate(NameID = seq(1, along.with = unique(Name))) >%>
ungroup()
This code gave the same number for all the column. So it gave me a number 1 for every NameID.
I Also tried the below code:
people >%>
gorup_by(Name) >%>
mutate(NameID = seq(1, length(unique(Name)))) >%>
ungroup()
And I came with the same result. I think that I might need to use an if function
or ifelse
, but I really don't know what should be the correct syntax.
sorry for the format, is my first time asking a question here and I need to learn to write things better