C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD

# How can I find the number of a vector's elements in another vector?

By : Enitsirhc Elise
Date : November 22 2020, 03:01 PM
Hope that helps
"[tabulate] gives me this error: Error in \$<-.data.frame(tmp, "comments_count", value = c(0L, 0L, : replacement has 25596 rows, data has 25597"
code :
``````df1 <- data.frame(v1 = c(1,1,1,4,5,5,4,1,2,3,5,6,2,1,5,2,3,4,1,6,4,2,3,5,1,2,5,4))
df2 <- data.frame(v2 = c(1,2,3,0,4,5,6,7))
df2\$count <- tabulate(factor(df1\$v1, df2\$v2))
# Error in `\$<-.data.frame`(`*tmp*`, count, value = c(7L, 5L, 3L, 0L, 5L,  :
#   replacement has 7 rows, data has 8
``````
``````df2\$count <- tabulate(factor(df1\$v1, df2\$v2), length(df2\$v2))
df2
# v2 count
# 1  1     7
# 2  2     5
# 3  3     3
# 4  0     0
# 5  4     5
# 6  5     6
# 7  6     2
# 8  7     0
``````

Share :

## C++: how to compare several vectors, then make a new sorted vector that contains ALL elements of all vectors

By : user2754919
Date : March 29 2020, 07:55 AM
will be helpful for those in need The algorithm you are looking for is usually named "merging". Basically you sort the two data sets and then look at data in pairs: if the keys are equal then you process and output the pair, otherwise you process and advance only the smallest one.
You must also handle the case where one of the two lists ends before the other (this can be avoided by using special flag values that are guaranteed to be higher than any value you need to process).
code :
``````std::map<std::string, int> data1, data2;
std::set<std::string> allkeys;

for (int i=0,n=vector1.size(); i<n; i++)
{
allkeys.insert(vector1[i].name);
data1[vector1[i].name] = vector1[i].value;
}

for (int i=0,n=vector2.size(); i<n; i++)
{
allkeys.insert(vector2[i].name);
data2[vector2[i].name] = vector2[i].value;
}

for (std::set<std::string>::iterator i=allkeys.begin(), e=allkeys.end();
i!=e; ++i)
{
const std::string& key = *i;
std::cout << key << data1[key] << data2[key] << std::endl;
}
``````

## How do i find a matrix of 150*25 from two vectors such that each vector elements multiply with each element of another v

By : Ashutosh
Date : March 29 2020, 07:55 AM
it fixes the issue To multiply each element of a row vector a with each element of another row vector b, we can use linear algebra. We transpose a to make it a column vector and then use matrix multiplication:
code :
``````a.' * b
``````

## Find number of common elements in given vectors from an array of vectors

By : Patrick M
Date : March 29 2020, 07:55 AM
Hope that helps If your vectors are sorted you can do that. You start from the largest of all first vector's element (as there cannot be a common element before) and you try to find the smallest largest common element. If there is one you start over from the remaining parts of the vectors. Otherwise you just look at the next plausible candidate.
Let v1, .., v4 denote the four choosen vector.
code :
``````Let i1=i2=i3=i4=0
While (i1 < v1.length, i2 <v2.length, i3 < v3.length, i4 < v4.length)
Let X = max(v1[i1],v2[i2],v3[i3],v4[i4])
Increase i1, i2, i3, i4 such that v1[i1]>=X, v2[i2]>=X, v3[i3]>=X, v4[i4]>=X
If v1[i1]=v2[i2]=v3[i3]=v4[i4]
count++
i1++
``````

## Initialize empty vector of vectors with elements of vector of vectors

Date : March 29 2020, 07:55 AM
this one helps. You made a simple error, which is easy to fix.
Your 2 dimensional vector
code :
``````std::vector<std::vector<std::string>> data_extract;
``````
``````std::vector<std::vector<std::string>> data_extract(array.size());
``````
``````data_extract.resize(array.size());
``````
``````std::vector<std::vector<std::string>> data_extract(array.size(),std::vector<std::string>(array[0].size(),""));
``````
``````while (event_iterator <= nr_of_events)
``````

## How to find the number of identical elements in two vectors?

By : RandomTechJunkie
Date : March 29 2020, 07:55 AM
seems to work fine tabulate works on integer vectors and is fast; match your letters to the universe of possible letters, then tabulate the index; use length(a) to ensure that there is one count for each possible value.