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

  • Home
  • SEARCH
  • 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 7159205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:11:33+00:00 2026-05-28T13:11:33+00:00

I am running expand.grid function. For a simple example, a <- c(1,2,3,X,Y,M) b is

  • 0

I am running expand.grid function. For a simple example,

a <- c(1,2,3,"X","Y","M") 
b is identical as b.

if I take expand.grid(a,b), it returns all pairs including diagonal elements — (1,1),(2,2),….(y,y), and also, elements which the first of pairs is larger than the second one –(2,1),(3,2)(x,1),…etc. (but, actually, not numerical comparison here as there are some characters like x,y) I want to exclude such pairs in output. How can I simply generate the output without them by using expand.grid function, Or, any other functions to do it?

  • 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-28T13:11:33+00:00Added an answer on May 28, 2026 at 1:11 pm

    A slight modification to Vincent Zoonekynd’s will take care of non-numerical factors:

    a <- c(1,2,3,"X","Y","M")
    eg <- expand.grid(a,a)
    eg2 <- eg[as.character(eg$Var1) < as.character(eg$Var2), ]
    

    Basically, what you need is to use string comparison instead of “plain” comparison that doesn’t work on factor variables.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Running ipconfig /all shows a Teredo Tunneling Pseudo-Interface. What is that? Does this have
I'm trying to expand on an idea from someone else's question, and running into
For example: We're running a two community sites on two domains (call them example.com
I have a request handler running in apache/mod_php which occasionally expands beyond the maximum
Running a rails site right now using SQLite3. About once every 500 requests or
running git instaweb in my repository opens a page that says 403 Forbidden -
Running into a problem where on certain servers we get an error that the
Running FxCop on my code, I get this warning: Microsoft.Maintainability : 'FooBar.ctor is coupled
Running OS X Leopard an MacBook Pro from Jan. 2008. I used to run
Running a ServiceHost with a single contract is working fine like this: servicehost =

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.