[R] replacing duplicate rows
ehlers at ucalgary.ca
Thu Jul 21 22:06:21 CEST 2011
On 2011-07-21 09:59, cassie jones wrote:
> Hi all,
> I have a matrix which looks like the following,
> Now, I want to replace the 2nd columns of those 4 rows which have duplicate
> entries in the 1st column. For example, x[2,1]=x[3,1]=3 and I want to
> replace x[3,2] by x[2,2]. Similarly, I want to replace x[5,2] with x[4,2],
> which means that for duplicate entries in the 1st column, I want to replace
> the corresponding entries in the 2nd column with its 1st entry of the
> duplicate row.
idx <- match(x[,1], x[,1])
x[,2] <- x[idx,2]
> Can anybody help me in this regard?
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> 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