Server Side Programming Articles

Page 1256 of 2109

How to initialize a data frame with variable names in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 5K+ Views

There are many ways to initialize a data frame in R but initializing with matrix is the best among them because creating the data frame with matrix help us to avoid entering the wrong number of columns and the wrong number of rows. After initializing the matrix, we can simply use as.data.frame to convert the matrix into a data frame and that’s it.Examplesdf1

Read More

How to sort one column of an R data frame in ascending and the other in descending order?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 338 Views

Sorting of columns of an R data frame is not difficult but sometimes we want to sort them in opposite orders, for example, we might want to sort some columns in ascending order and some in descending order. This variation in sorting purpose makes it a little complicated. Therefore, we can use negation with sort function to sort the columns that we want to sort in descending order.ExampleConsider the below data frame −set.seed(111) x1

Read More

How to remove last few rows from an R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 2K+ Views

An R data frame can contain a very large number of rows and we might want to get rid of some rows if they’re not supposed to be helpful in our data analysis. Therefore, we can remove these rows prior to starting the analysis process. We can say that this removal of some rows is a part of data cleaning and obviously data cleaning helps us creating a smooth data set for analysis. In R, we can simply use head function to remove last few rows from an R data frame, also we can store them as a new data ...

Read More

Find the probability of reaching all points after N moves from point N in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 206 Views

Suppose we have a number N this represents the initial position of the person on the number line. We also have L which is the probability of the person of going left. We have to find the the probability of reaching all points on the number line after completing N moves from point N. Each move can be either to the left or to the right.So, if the input is like n = 2, l = 0.5, then the output will be [0.25, 0, 0.5, 0, 0.25]To solve this, we will follow these steps −high := 1 - lowDefine an ...

Read More

Find the value of the function Y = (X^6 + X^2 + 9894845) % 981 in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 178 Views

Suppose we have given function like f(x) = (x^6 + x^2 + 9894845) % 971, now for a given value of x, we have to find the value of f(x).So, if the input is like 5, then the output will be 469To solve this, we will follow these steps −Define a function power_mod(), this will take base, exponent, modulus, base := base mod modulusresult := 1while exponent > 0, do −if exponent is odd, then −result := (result * base) mod modulusbase := (base * base) mod modulusexponent = exponent /2return resultFrom the main method do the following −return power_mod(n, ...

Read More

What happens when a virtual function is called inside a non-virtual function in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 378 Views

In this section we will discuss about interesting facts about virtual classes in C++. We will see two cases first, then we will analyze the fact.At first execute the program without using any virtual function.The execute the program using any virtual function under non-virtual function.ExampleLet us see the following implementation to get better understanding −#include using namespace std; class BaseClass { public:    void display(){       cout

Read More

What happens when more restrictive access is given to a derived class method in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 167 Views

In this section we will discuss about interesting facts restrictive access of derived class methods in C++. We will see some examples and analyze the output to know more about restrictions of using derived class methods in C++.Example (C++)Let us see the following implementation to get better understanding −#include using namespace std; class BaseClass { public:    virtual void display(){       cout

Read More

Computing index using pointers returned by STL functions in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 253 Views

In this section we will see how to generate index using pointers that are returned by STL in C++. As we know many inbuilt functions in C++ return the pointers to the position in memory which provides the address of desired number, but it has no relation with the actual index in the container of the returned value. As an example, to determine maximum element in a code, we use std::max_element() function, this does not return the index of the desired element, but return the address in memory. But sometimes, we need to get the index from that address. Here ...

Read More

Gaussian Filter Generation in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 2K+ Views

As we know the Gaussian Filtering is very much useful applied in the field of image processing. It is used to reduce the noise of an image. In this section we will see how to generate a 2D Gaussian Kernel. Gaussian Distribution for generating 2D kernel is as follows.$$G(x,y)= \frac{1}{2\Pi\:\sigma^{2}}e^{\frac{x^{2}+y^{2}}{2\sigma^{2}}}$$ExampleLet us see the following implementation to get better understanding −#include #include #include #define PI 3.1415 using namespace std; void calc_filter(double kernel[][5]) {    double sigma = 1.0;    double p, q = 2.0 * sigma * sigma;    double sum = 0.0;    for (int x = -2; x

Read More

Generating Test Cases (generate() and generate_n() in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 377 Views

In this section we will see how we can use C++ STL function to generate test cases. Sometimes generating test cases for array programs can be very complicated and inefficient process. C++ provides two methods to generate test cases. These methods are as follows −The generate() methodThe C++ function std::algorithm::generate() assigns the value returned by successive calls to gen to the elements in the range of first to last. It takes three parameters first, last and gen, these are forward iterator to the initial position, backward iterator to the final position and generator function that is called with no argument, ...

Read More
Showing 12551–12560 of 21,090 articles
Advertisements