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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:13:32+00:00 2026-06-03T01:13:32+00:00

The following is dataset, I need to make two. ID <- 1:4 pos <-

  • 0

The following is dataset, I need to make two.

ID <- 1:4
pos <- c(0, 245, 567, 871)
A1 <- c("A/B", "A/A", "B/B", "A/A")
B1 <- c("B/B", "C/C", "C/B", "D/A")
C1 <- c("B/B", "C/C", "-/-", "D/A")
mydf2 <- data.frame (ID, A1, B1, C1, pos)

I are interested to have 2:4 column in one dataset

mydf3 <- mydf2[,2:4]

Now I want rest of variables in different dataframe.

mydf4 <-  mydf2[, names(mydf2) != names(mydf3)]

Am I missing something obvious ?

Warning message:
In names(mydf2) != names(mydf3) :
  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-03T01:13:33+00:00Added an answer on June 3, 2026 at 1:13 am

    You want instead:

    mydf4 <- mydf2[, ! names(mydf2) %in% names(mydf3)]
    

    You got the error message you did because the != operator performs an elementwise comparison of its two vector arguments. When the vectors have different lengths, it recycles the shorter one to fill it out to the length of the longer one. You passed it vectors of length 3 and 5, and since neither number is a divisor of the other, it had an inkling that you might not actually be wanting that recycling behavior and warned you about what it was doing. (Compare the results of 2:4 != 1:6 to 2:4 != 1:5 to see how this could have been even more puzzling to debug.)

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

Sidebar

Related Questions

I have the following data that basically I only need a few bits of
I have the following: sets = DataSet.all.group_by{ |data| [data.project_id, -, data.thread_id].join( ) } <%
I have following dataset Id Title Group 1 title1 A 2 title2 A 3
I have the following sample dataset (below and/or as CSVs here: http://goo.gl/wK57T ) which
I have big dataset (but the following is small one for example). I can
I have the following data set that I am trying to plot with ggplot2,
I have the swiss data set provided by R, which has the following form:
I have a grid view that is data bound to a dataset. In a
Suppose that I have the following code: private void UpdateDB(QuoteDataSet dataSet, Strint tableName) {
The problem: I often need to select a set of variables from a data.frame

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.