[R] Loops to assign a unique ID to a column

2011-08-02 Thread Chandra Salgado Kent
Dear R help, I am fairly new in data management and programming in R, and am trying to write what is probably a simple loop, but am not having any luck. I have a dataframe with something like the following (but much bigger): Dates-c(12/10/2010,12/10/2010,12/10/2010,13/10/2010,

Re: [R] Loops to assign a unique ID to a column

2011-08-02 Thread ONKELINX, Thierry
Dear Chandra, You're on the wrong track. You don't need for loops as you can do this vectorised. as.numeric(interaction(data$Groups, data$Dates, drop = TRUE)) Best regards, Thierry -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]

Re: [R] Loops to assign a unique ID to a column

2011-08-02 Thread David L Carlson
How about this? indx - unique(cbind(Dates, Groups)) indx DatesGroups [1,] 12/10/2010 A [2,] 12/10/2010 B [3,] 13/10/2010 A [4,] 13/10/2010 B [5,] 13/10/2010 C indx - data.frame(indx, id=1:nrow(indx)) indx Dates Groups id 1 12/10/2010 A 1 2 12/10/2010

Re: [R] Loops to assign a unique ID to a column

2011-08-02 Thread Bert Gunter
Whoa! 1. First and most important, there is very likely no reason you need to do this. R can handle multiple groupings automatically in fitting and plotting without creating artificial labels of the sort you appear to want to create. Please read an Intro to R and/or get help to see how. 2. The