Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4265460
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:37:37+00:00 2026-05-21T06:37:37+00:00

R Version 2.11.1 32-bit on Windows 7 I get a data set as below:

  • 0

R Version 2.11.1 32-bit on Windows 7

I get a data set as below:

USER_A USER_B SCORE
1        6      0.2
1        7      0.1
1        10     0.15
2        6      0.2
2        9      0.12
3        8      0.15
3        9      0.3

the USER_A is 1:3 and the USER_B is 6:10. Now I need to output the USER_A with the ranking of USER_B by their SCORE:

USER_A      ranking of USER_B
1  3  1  2  #the ranking of USER_B 6,7,10(which belong to USER_A 1)
2  2  1     #the ranking of USER_B 6,9(which belong to USER_A 2)
3  1  2     #the ranking of USER_B 8,9(which belong to USER_A 3)

in fact, I just need to output the ranking:

3 1 2
2 1
1 2

it is upset because the length of each row is different! I could not store them in a matrix and then output them.

Could anyone help me solve this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T06:37:38+00:00Added an answer on May 21, 2026 at 6:37 am
    df <- read.table(con <- textConnection("USER_A USER_B SCORE
    1        6      0.2
    1        7      0.1
    1        10     0.15
    2        6      0.2
    2        9      0.12
    3        8      0.15
    3        9      0.3
    "), header = TRUE)
    close(con)
    

    One way is to split the data:

    sdf <- with(df, split(SCORE, f = USER_A))
    lapply(sdf, rank)
    

    The last line gives:

    > lapply(sdf, rank)
    $`1`
    [1] 3 1 2
    
    $`2`
    [1] 2 1
    
    $`3`
    [1] 1 2
    

    An alternative is to use aggregate() as in:

    aggregate(SCORE ~ USER_A, data = df, rank)
    

    Which returns:

    > (foo <- aggregate(SCORE ~ USER_A, data = df, rank))
      USER_A   SCORE
    1      1 3, 1, 2
    2      2    2, 1
    3      3    1, 2
    

    But the output is a bit different here, now we have a data frame, with the second component SCORE being a list, just like the lapply() version outputted:

    > str(foo)
    'data.frame':   3 obs. of  2 variables:
     $ USER_A: int  1 2 3
     $ SCORE :List of 3
      ..$ 0: num  3 1 2
      ..$ 1: num  2 1
      ..$ 2: num  1 2
    > foo$SCORE
    $`0`
    [1] 3 1 2
    
    $`1`
    [1] 2 1
    
    $`2`
    [1] 1 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

R Version 2.11.1 32-bit on Windows 7 I get the data train.txt as below:
I am running 64-bit Windows 7 and the Python 2.6 installation (64-bit version). In
1) I have installed 32 bit version wamp 2.2E, on windows XP 32bit. The
To preface, I am on Windows 7 (64-bit), running Java version 6 (update 33)
I am usint the 64-bit version of Enthought Python to process data across multiple
In x64 bit version of windows, i see that are also x86 bit directories.
When Matlab is installed in its 64 bit version, it can use only 64
Specifically curious if IIS 5.1 has a 64 bit version, but I'm guessing only
Is there a way to determine the JVM version (32-bit or 64-bit) in C#?
I am using Jasper Server 4.5.0 32-bit version. When I click on Next after

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.