[R] extracting duplicated elements
dxc13
dxc13 at health.state.ny.us
Thu Aug 23 16:52:19 CEST 2007
Can anyone help me solve this problem...thanks!
Consider a data frame, namely v, as such:
> v
X1 X2 X3 X4 X5 X1 X2 X3 X4 X5
x1 1 2 -1 -1 -1 1 2 -1 -1 -1
y1 1 2 -1 -1 -1 1 2 3 -1 -1
What I would like to do is to create an array or data frame with only the
elements that appear in the data frame more than once and are >= 0.
I try this...
> v[v>=0]
[1] 1 1 2 2 1 1 2 2 3
which returns all >= 0 elements, but they are not in their respective rows
from the original data frame. I have tried using the duplicated()
function and can't seem to get it to work correctly.
Essentially, the outcome I am trying to get is a df or array looking like:
step 1...achieve this out of original df
[1] 1 2 1 2
[2] 1 2 1 2 3
(the blank element in row 1, position 5 can be just be NA)
step 2...take the above and get this...only the duplicated elements
[1] 1 2
[2] 1 2
--
View this message in context: http://www.nabble.com/extracting-duplicated-elements-tf4318034.html#a12295213
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list