[R] Create an identifier variable

R. Michael Weylandt michael.weylandt at gmail.com
Tue Nov 29 23:35:49 CET 2011

Try something like this:

Suppose your data object is called df:

cbind(paste("sd", 1:NROW(df), sep = ""), df)

If you are just moving from SAS check out the website (and books
associated with) http://r4stats.com -- it's got some tutorials on
moving from other platforms to R.


On Tue, Nov 29, 2011 at 2:48 PM, hyunjeehale <hyunjee.hale at gmail.com> wrote:
> I am needing to create a new identifier variable for a data set which has no
> ID variable in the original file. I am basically wanting to take the count
> of each row and add "sd" in front of it - so it would look like so
> sd1
> sd2
> sd3
> sd4
> sd5 etc.......
> I have no idea how to do this. I am a SAS user trying to learn R. This
> question may have been answered previously, but I could be searching for it
> incorrectly. Thank you for any assistance you can provide.
> HyunJee
> --
> View this message in context: http://r.789695.n4.nabble.com/Create-an-identifier-variable-tp4120548p4120548.html
> Sent from the R help mailing list archive at Nabble.com.
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list