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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:32:14+00:00 2026-06-15T13:32:14+00:00

I have two large vectors: A: https://dl.dropbox.com/u/22681355/A.csv B: https://dl.dropbox.com/u/22681355/B.csv A has over 20000 entries

  • 0

I have two large vectors:

A: https://dl.dropbox.com/u/22681355/A.csv
B: https://dl.dropbox.com/u/22681355/B.csv

A has over 20000 entries but only 1350 unique entries.
B is a random number generated from 1 to 9 exactly 1350 times

I would like to assign values from B to A such that the same values in A get the same values in B. e.g. if there are multiple 1’s each 1 should get the same number from B.

I have been using the A[B] command but after the 18000th entry I get NAs

What is the proper way of doing this?

code:

A<-read.csv("A.csv")
B<-read.csv("B.csv")

A[B]
  • 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-15T13:32:15+00:00Added an answer on June 15, 2026 at 1:32 pm
    1. read.csv() creates a data frame, not a vector.
    2. You probably mean B[A] which for each element in A gets the value of B at the index of that element’s value. Since A’s values range from 1 to 1899 it exceeds B’s size of 1349. For those elements outside the bounds of B, NAs get introduced.

    The correct way to doing what you want to achieve is

    A = read.table("http://dl.dropbox.com/u/22681355/A.csv")
    B = read.table("http://dl.dropbox.com/u/22681355/B.csv")
    A = A$V1
    B = B$V1
    A = as.factor(A)
    
    B[match(A,levels(A))]
    

    match(A,levels(A)) will return a vector of the same length as A that for each element contains the position of the element of A in its factor’s levels, i.e. a number between 1 and 1350 (1350 distinct values). If A was as.factor(c(1,1,3,5,5,7)), levels(A) would be c(1,3,5,7) and match(A,levels(A)) would be c(1,1,2,3,3,4), i.e. the position of the element in it’s levels.

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

Sidebar

Related Questions

I have two large source trees. One of them has some out of date
I have two large vectors, I am trying to do some sort of element
I have two arrays First array has large number of words, i have 2nd
I have two large dictionaries with unique keys but possibly overlapping values. I want
I have two large identical-sized files. One is ASCII plain text, and the other
I have two large (~100 GB) text files that must be iterated through simultaneously.
I have two large tables in MySQL, one containing about 6,00,000 records and another
1) My question is that, when i have two large table which cannot be
I have two quite large tables, let's call them 'authors' and 'articles'. Every row
I have two batch files which is used to run a large C++ build,

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.