Articles on Trending Technologies

Technical articles with clear explanations and examples

How to find the number of unique values in each row of an R data frame?

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

To find the number of unique values in each row of an R data frame, we can use apply function with length and unique function. For example, if we have a data frame called df that contains multiple columns then the number of unique values in each row of df can be found by using the command apply(df, 1, function(x) length(unique(x))).Example1Consider the below data frame −> x1 x2 x3 x4 df1 df1Output   x1 x2 x3 x4 1   3  1  1  2 2   3  2  0  2 3   3  2  0  1 4   3  0  3  1 ...

Read More

Remove tuples having duplicate first value from given list of tuples in Python

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 672 Views

When it is required to remove tuples that have a duplicate first value from a given set of list of tuples, a simple 'for' loop, and the 'add' and 'append' methods can be used.Below is a demonstration for the same −Examplemy_input = [(45.324, 'Hi Jane, how are you'), (34252.85832, 'Hope you are good'), (45.324, 'You are the best.')] visited_data = set() my_output_list = [] for a, b in my_input:    if not a in visited_data:       visited_data.add(a)       my_output_list.append((a, b)) print("The list of tuple is : ") print(my_input) print("The list of tuple after removing ...

Read More

How to perform paired t test for multiple columns in R?

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

When we have a factor column in an R data frame that has two levels and multiple numerical columns then we can apply paired-test on this data frame but the data must be collected for same subjects, otherwise it will not be a paired data. The t.test application on the data discussed here can be done by using the command lapply(df[-1], function(x) t.test(x~df$group)), where group is the factor column and lies at the first position in the data frame, x contains all the numerical columns in the data frame, and all these columns are stored in data frame called df.ExampleConsider ...

Read More

How to extract the last row from list of a data frame in R?

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

Suppose we have two frames each having 5 columns that are stored in a list in R and we want to extract the last row from each data frame then we can use the lapply function. For example, if we have a list called LIST that contains the data frames described above then we can extract the last row from each data frame using the command lapply(LIST, tail, 1).ExampleConsider the below list of data frames −> x1 x2 df1 y1 y2 df2 z1 z2 df3 List ListOutput[[1]]    x1 x2 1   6  5 2   6  5 3   ...

Read More

Modifying tuple contents with list in Python

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 281 Views

When it is required to modify the list of tuple, the 'zip' method and the list comprehension can be used.The zip method takes iterables, aggregates them into a tuple, and returns it as the result.The list comprehension is a shorthand to iterate through the list and perform operations on it.A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on). A list of tuple basically contains tuples enclosed in a list.Below is a demonstration for the same −Examplemy_list_1 = [('Hi', 1), ('there', 2), ('Jane', 3)] my_list_2 = [45, ...

Read More

How to convert a column with missing values to binary with 0 for missing values in R?

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

To convert a column with missing values to binary with 0 for missing values, we can use as.integer function with complete.cases for the data frame column. For example, if we have a data frame called df that contains a column x which has some missing values then the column x can be converted to binary with 0 for missing values by using the command −as.integer(complete.cases(df$x))Example1Consider the below data frame −> x1 y1 df1 df1Output   x1 y1 1  NA  2 2   2  5 3   2 10 4   2  2 5   2  4 6  NA  7 7  NA ...

Read More

Split tuple into groups of n in Python

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 620 Views

When it is required to split the tuple into 'n' groups, the list comprehension can be used. A tuple is an immutable data type. It means, values once defined can't be changed by accessing their index elements. If we try to change the elements, it results in an error. They are important contains since they ensure read-only access.The list comprehension is a shorthand to iterate through the list and perform operations on it.Below is a demonstration for the same −Examplemy_tuple = (12, 34, 32, 41, 56, 78, 9, 0, 87, 53, 12, 45, 12, 6) print ("The tuple is ...

Read More

What to do if numeric values are being read as character in R?

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

If the numeric values are being read as character then we need to convert them into numeric values by using the function as.numeric. For example, if we have a data frame called df that contains a column say x which has numerical values stored in character format then we can convert them into numeric values using the command as.numeric(df$x).ExampleConsider the below data frame −x1

Read More

How to find the column that has the largest sum in R?

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

To find the column that has the largest sum, we can use sort function for sorting in decreasing order with colSums and accessing the first element of the output which will be the largest sum. For example, if we have a data frame called df that contains multiple columns then the column that has the largest sum can be found by using the command −str(sort(colSums(df[, 1:length(df)]), decreasing=TRUE)[1])Example1Consider the below data frame −> x1 x2 x3 x4 df1 df1Output   x1 x2 x3 x4 1   3  4  4  5 2   6 10  3  3 3   6  5  2  5 ...

Read More

Selective value selection in list of tuples in Python

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 177 Views

When it is required to find the selective value in a list of tuples, the 'dict' method, the 'get' method and the list comprehension can be used.The list comprehension is a shorthand to iterate through the list and perform operations on it. A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).A list of tuple basically contains tuples enclosed in a list.The 'dict' method creates a dictionary. It contains key value pairs, which are unordered, and indexed.The 'get' method returns the value of a specific key when ...

Read More
Showing 1731–1740 of 61,248 articles
« Prev 1 172 173 174 175 176 6125 Next »
Advertisements