Server Side Programming Articles

Page 138 of 2107

How to find the mean of multiple columns based on a character column in R?

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

If we have a character column that means we are more likely to have duplicated values in that column hence finding the mean of numerical columns based on the values in character column cannot be done directly. For this purpose, we can use aggregate function as shown in the below examples.Example1Consider the below data frame −set.seed(214) x1

Read More

What are parametrized constructors in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 11-Mar-2026 14K+ Views

A constructor is similar to method and it is invoked at the time creating an object of the class, it is generally used to initialize the instance variables of a class. The constructors have same name as their class and, have no return type.Parameterized constructorsA parameterized constructor accepts parameters with which you can initialize the instance variables. Using parameterized constructor, you can initialize the class variables dynamically at the time of instantiating the class with distinct values.Syntaxpublic class Sample{    Int i;    public sample(int i){       this.i = i;    } }Examplepublic class Test {    String ...

Read More

How to create a default constructor in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 11-Mar-2026 4K+ Views

Default constructor (No-arg constructor)A no-arg constructor doesn’t accepts any parameters, it instantiates the class variables with their respective default values (i.e. null for objects, 0.0 for float and double, false for Boolean, 0 for byte, short, int and, long).There is no need to invoke constructors explicitly these are automatically invoked at the time of instantiation.Rules to be rememberedWhile defining the constructors you should keep the following points in mind.A constructor does not have return type.The name of the constructor is same as the name of the class.A constructor cannot be abstract, final, static and Synchronized.You can use the access specifiers ...

Read More

How to find the sum by distinct column for factor levels in an R data frame?

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

If the data frame contains a factor column and some numerical columns then we might want to find the sum of numerical columns for the factor levels. For this purpose, we can use aggregate function. For example, if we have a data frame df that contains a factor column defined by Group and some numerical columns then the sum by distinct column for factor levels can be calculated by using aggregate(.~Group,data=df,sum)Example1Class

Read More

How to replace missing values with row means in an R data frame?

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

If we have similar characteristics in each column of an R data frame then we can replace the missing values with row means. To replace the missing values with row means we can use the na.aggregate function of zoo package but we would need to use the transposed version of the data frame as na.aggregate works for column means.Example1Consider the below data frame −x1

Read More

How to check if a variable contains number greater than 1 in an R data frame?

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

The variables in an R data frame are referred to as the columns of the data frame. Sometimes we have a threshold value for a particular column and we need to check whether all the values in that column are greater than or less than the threshold. For this purpose, we can make use of ifelse function as shown in the below examples.Example1y

Read More

What are various ways to compare time values in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 11-Mar-2026 2K+ Views

The LocalTime class represents the local time i.e. the time without time zone. This class provides various methods such as isBefore(), isAfter() and, isEqual() to compare two times.Exampleimport java.time.LocalTime; public class Test {    public static void main(String args[]) {         LocalTime Time1 = LocalTime.of(10, 15, 45);       LocalTime Time2 = LocalTime.of(07, 25, 55);             Boolean bool1 = Time1.isAfter(Time2);         Boolean bool2 = Time1.isBefore(Time2);       if(bool1){          System.out.println(Time1+" is after "+Time2);       }else if(bool2){          System.out.println(Time1+" is ...

Read More

How to compare two dates in String format in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 11-Mar-2026 8K+ Views

The java.text.SimpleDateFormat class is used to format and parse a string to date and date to string.One of the constructors of this class accepts a String value representing the desired date format and creates SimpleDateFormat object. To parse/convert a string as a Date object Instantiate this class by passing desired format string.Parse the date string using the parse() method.The util.Date class represents a specific instant time This class provides various methods such as before(), after() and, equals() to compare two datesExampleOnce you create date objects from strings you can compare them using either of these methods as shown below −import java.text.ParseException; import ...

Read More

How to parse date sting to date in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 11-Mar-2026 2K+ Views

You can parse a string containing a data to date value using the following ways −The constructor SimpleDateFormat class accepts a String value representing the desired date format and creates this object. You can parse the date string using the parse() method of this class.The parse() method of the LocalDate class accepts a String value representing a date and returns a LocalDate object.The DateUtils provides utility to format date you can find it in apache.commons package. The parseDate() method of the DateUtils class accepts a format string and a date string as parameters and returns a Date object.The parse() method of ...

Read More

How to extract unique values in multiple columns in an R data frame using a single line code?

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

To extract unique values in multiple columns in an R data frame, we first need to create a vector of the column values but for that we would need to read the columns in matrix form. After that we can simply unique function for the extraction. To understand how it works check out the below examples.Consider the below data frame −Examplex1

Read More
Showing 1371–1380 of 21,061 articles
« Prev 1 136 137 138 139 140 2107 Next »
Advertisements