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 8974733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:44:18+00:00 2026-06-15T18:44:18+00:00

Possible Duplicate: Select only the first rows for each unique value of a column

  • 0

Possible Duplicate:
Select only the first rows for each unique value of a column in R

I have a matrix of the following form:

col1 col2

1    2   
1    2    
1    2   
1    2   
1    2
2    5
2    5
2    5
3    7
3    7
3    7
3    7
3    7
3    7
3    7
3    7
4    2 
4    2 
4    2

I would like to select all the unique rows based on ‘col1’.

which in this case would be the first row from each unique value in col1:

subset:

col1   col2
1      2 
2      5
3      7
4      2

Here’s what I’ve tried:

https://dl.dropbox.com/u/22681355/matrix.csv
mat<-read.csv("matrix.csv")
sub<-unique(mat$V1)
subset(mat, mat==c(sub)

It spits out much more than I would expect to get and I get this error mesage:

Warning message:
In contacts$V1 == c(g) :
longer object length is not a multiple of shorter object length

  • 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-06-15T18:44:19+00:00Added an answer on June 15, 2026 at 6:44 pm

    You can use the unique function:

    unique(mat$V1) # and not matrix$v1
    [1]   44  281 1312
    

    You can also write

    unique(mat)
    

    and it will give you unique lines (I tried it on your file).

    If you want to select on V1s values, you can do this:

    > mat[!duplicated(mat$V1), ]
           X   V1 V2 V3 V4  V5 V6 V7 V8 V9 V10
    1   1547   44 14  1  2 100 17  0  0  0   0
    23  5385  281 67  2 10 100 10  0  0  0   0
    33 17347 1312  1  2  6 100  8  0  0  0   0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Rails: select unique values from a column Lets say I have 5000
Possible Duplicate: How to only select numeric data from mysql? I have a column
Possible Duplicate: Remove Duplicate Rows Leaving Oldest Row Only? I have a posts_table in
Possible Duplicate: MySQL returns only one row I wonder how to select all rows
Possible Duplicate: Multiple select options in one row I have the following code but
Possible Duplicate: JavaScript - populate drop down list with array I have following select
Possible Duplicate: CSS Select Selector What is the CSS equivalent to the following when
Possible Duplicate: Writing an SQL query to SELECT item from the following table I
Possible Duplicate: SQL Server: Only last entry in GROUP BY I have a table
Possible Duplicate: MySQL returns only one row In Terminal mysql> select image,title,price from test;

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.