Articles on Trending Technologies

Technical articles with clear explanations and examples

How to create an ordinal variable in R?

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

An ordinal variable is a type of categorical variable which has natural ordering. For example, an ordinal variable could be level of salary something defined with Low, Medium, and High categories here we have three categories but there exists a natural order in these categories as low salary is always less than the medium, medium is always less than high. To create an ordinal variable in R, we can use the order argument along with factor function while creating the variable. Follow the below steps to create an ordinal variable in R −Create a categorical column with factor function where ...

Read More

Python – Average digits count in a List

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 265 Views

When it is required to count average digits in a list, a simple iteration, the ‘str’ method and the ‘/’ operator is used.Below is a demonstration of the same −Examplemy_list = [324, 5345, 243, 746, 432, 463, 946787] print("The list is :") print(my_list) sum_digits = 0 for ele in my_list:    sum_digits += len(str(ele))     my_result = sum_digits / len(my_list) print("The result is :") print(my_result)OutputThe list is : [324, 5345, 243, 746, 432, 463, 946787] The result is : 3.5714285714285716ExplanationA list is defined and displayed on the console.A variable is initialized to 0.The list is ...

Read More

Python – All combinations of a Dictionary List

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 1K+ Views

When it is required to display all the combinations of a dictionary list, a simple list comprehension and the ‘zip’ method along with the ‘product’ method are used.Below is a demonstration of the same −Examplefrom itertools import product my_list_1 = ["python", "is", "fun"] my_list_2 = [24, 15] print("The first list is :") print(my_list_1) print("The second list is :") print(my_list_2) temp = product(my_list_2, repeat = len(my_list_1)) my_result = [{key : value for (key , value) in zip(my_list_1, element)} for element in temp] print("The result is :") print(my_result)OutputThe first list is : ['python', 'is', 'fun'] The second ...

Read More

How to sort 0,1,2 in an Array (Dutch National Flag) without extra space using C#?

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

We need to take three-pointers, low, mid, high. We will use low and mid pointers at the start, and the high pointer will point at the end of the given array.If array [mid] =0, then swap array [mid] with array [low] and increment both pointers once.If array [mid] = 1, then no swapping is required. Increment mid pointer once.If array [mid] = 2, then we swap array [mid] with array [high] and decrement the high pointer once.Time complexity − O(N)Exampleusing System; namespace ConsoleApplication{    public class Arrays{       private void Swap(int[] arr, int pos1, int pos2){     ...

Read More

Python – Sort Matrix by Row Median

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 277 Views

When it is required to sort matrix by row median, a method is defined that uses the ‘median’ method to determine the result.Below is a demonstration of the same −Examplefrom statistics import median def median_row(row):    return median(row) my_list = [[43, 14, 27], [13, 27, 24], [32, 56, 18], [34, 62, 55]] print("The list is :") print(my_list) my_list.sort(key = median_row) print("The result is :") print(my_list)OutputThe list is : [[43, 14, 27], [13, 27, 24], [32, 56, 18], [34, 62, 55]] The result is : [[13, 27, 24], [43, 14, 27], [32, 56, 18], [34, 62, ...

Read More

How to display axes ticks and labels inside the plot using ggplot2 in R?

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

To display axes ticks and labels inside the plot using ggplot2 in R, we can follow the below steps −First of all, create a data frame.Then, create a plot using ggplot2.After that create the same plot with theme function to change the position of axes ticks and labels.Create the data frameLet's create a data frame as shown below −x

Read More

Python program to Sort Strings by Punctuation count

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 310 Views

When it is required to sort strings by punctuation count, a method is defined that takes a string as a parameter and uses list comprehension and ‘in’ operator to determine the result.Below is a demonstration of the same −Examplefrom string import punctuation def get_punctuation_count(my_str):    return len([element for element in my_str if element in punctuation]) my_list = ["python@%^", "is", "fun!", "to@#r", "@#$learn!"] print("The list is :") print(my_list) my_list.sort(key = get_punctuation_count) print("The result is :") print(my_list)OutputThe list is : ['python@%^', 'is', 'fun!', 'to@#r', '@#$learn!'] The result is : ['is', 'fun!', 'to@#r', 'python@%^', '@#$learn!']ExplanationThe required packages are ...

Read More

How to subset rows based on criterion of multiple numerical columns in R data frame?

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

If we want to create a subset of a data frame based on multiple numerical columns then we can follow the below steps −Creating a data frame.Subsetting the data frame with the help of filter function of dplyr package.Create the data frameLet's create a data frame as shown below −x1

Read More

How to create a graph in base R with multiple shades of a particular color?

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

To create a graph in base R with multiple shades of a particular color, we can follow the below steps −First of all, create color shades using colorRampPalette then plot a graph.Use the color shades to create the graph.Example 1Create the color shadesUsing colorRampPalette function to create the color shades between red and darkred color then creating the plot −Color

Read More

How to rotate an array k time using C#?

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

Given an array and number k, the problem states that we have to rotate the array k times.If the given number is 3 then the array must be rotated 3 times.Create a function reverse which takes the array, start and end as a parameter.In the 1st step call reverse method from 0 to array length.In the 2nd step call the reverse method from 0 to k-1.In the 3rd step call the reverse method from k+1 to array length.Exampleusing System; namespace ConsoleApplication{    public class Arrays{       public void ReverseArrayKTimes(int[] arr, int k){          Reverse(arr, 0, ...

Read More
Showing 511–520 of 61,248 articles
« Prev 1 50 51 52 53 54 6125 Next »
Advertisements