0

I have a dataframe that I have scrambled through matching and ordering. I ask for a position in the dataframe by matching. Now I want to take that position and get the row.names?

tmp<-match(paste(dat$data), finaltable$data);
> tmp
[1]   3  26  32  38 

    data Duplicate Digit6  Digit7
45  21305    137401 137401 2017681
82  21342    137402 137402 2017731
81  21341    137403 137403 2017632
66  21326    137406 137406 2017775
64  21324    137407 137407 2017745
80  21340    137408 137408 2017768

I need a piece of code that outputs the rowname based on the position outputted from tmp?

4
  • 2
    Like rownames(finaltable)[tmp]? What exactly are you showing the output of above(dat or finatable or some subset)? And what is the desired output? Commented Aug 4, 2014 at 21:12
  • at MrFlick, yes this is it. so what you are doing here is extracting the rownames of finaltable, by positions specified by tmp? Commented Aug 4, 2014 at 21:19
  • Yes. It's hard to tell if that's what you wanted because your example wasn't exactly complete or reproducible. Commented Aug 4, 2014 at 21:21
  • yeah, sorry about that. The data I am working with is sensitive. Overall, this is what I wanted. Thanks Commented Aug 4, 2014 at 21:22

1 Answer 1

3

If we create some sample data with

set.seed(15)
finaltable<-data.frame(
    data=1:10, 
    count=rpois(10,10), 
    row.names=letters[1:10])
dat<-data.frame(
     data=sample(finaltable$data,3), 
     value=runif(3))

And then do the matching

tmp<-match(paste(dat$data), finaltable$data);

we can get the rownames from the finaltable for the matched rows with

rownames(finaltable)[tmp]
# [1] "h" "d" "a"
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.