Server Side Programming Articles

Page 1125 of 2109

How to delete a list element that only contains NA in R?

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

To delete a list element that only contains NA, we can use Filter function with Negate function. For example, if we have a list called LIST that contains one or more elements having all NA’s then we can delete those elements using the command −Filter(Negate(anyNA),LIST)Example1Consider the below list −List1

Read More

How to recode factors in R?

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

Sometimes we have factor levels that can be combined or we want to group those levels in a single level. It is mostly done in situations where we have only one value for a particular factor level or there exists some theoretical concept that leads to combining the factor levels. For example, if we have a data frame called df that contains a factor column say x having four categories A, B, C, and D then they can be grouped into A and B as −df$x[df$x %in% c("A","B")]

Read More

Casting in Rust Programming

Mukul Latiyan
Mukul Latiyan
Updated on 11-Mar-2026 478 Views

Casting or explicit conversion is only allowed in Rust, there’s no implicit conversion that the compiler of Rust does for us. It is known that, in many cases, implicit conversion can lead to data losses, which is not a good thing.Rules for converting between different types is pretty similar to C. In Rust though, we make use of as keyword when we want to convert from one type to another.Example:Consider the following example:// Suppress all warnings from casts which overflow. #![allow(overflowing_literals)] fn main() {    let decimal = 65.43_f32;    // Error! No implicit conversion    // let ...

Read More

How to create duplicate matrices and merge them together in R?

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

To create duplicate matrices, we can use replicate function that will repeat the original matrix and if we want to merge those matrices together then we can use rbind with do.call. For example, if we have a matrix called M then creation of it’s one duplicate and merging them together can be done using the command −do.call(rbind,replicate(2,M,simplify=FALSE))ExampleM

Read More

How to find the percentage for frequencies stored in a vector with two decimal places in R?

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

To find the percentage for frequencies stored in a vector with two decimal places can be done with the help of sum function and round function. For example, if we have a vector of frequencies say x then the percentage of these frequencies can be found by using the command round((x/sum(x))*100,2). Check out the below examples to understand how it works.Example1Frequency1

Read More

How to find the mean squared error for linear model in R?

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

To find the mean squared error for linear model, we can use predicted values of the model and find the error from dependent variable then take its square and the mean of the whole output. For example, if we have a linear model called M for a data frame df then we can find the mean squared error using the command mean((df$y-predict(M))^2).Example1Consider the below data frame −x1

Read More

How to change the code "Yes" to 1 in an R data frame column?

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

To change the code “Yes” to 1, we can use ifelse function and set the Yes to 1 and others to 0. For example, if we have a data frame called df that contains a character column x which has Yes and No values then we can convert those values to 1 and 0 using the command ifelse(df$x=="Yes",1,0).Example1Consider the below data frame −Agree

Read More

From and Into Traits In Rust Programming

Mukul Latiyan
Mukul Latiyan
Updated on 11-Mar-2026 382 Views

From and Into are two traits that Rust provides us. They are internally linked.From TraitWe make use of From trait when we want to define a trait to how to create itself from any other type. It provides a very simple mechanism with which we can convert between several types.For example, we can easily convert str into a String.ExampleConsider the example shown below:fn main() {    let my_str = "hello";    let my_string = String::from(my_str);    println!("{}", my_string); }OutputhelloWe can even convert our own types.ExampleConsider the example shown below:use std::convert::From; #[derive(Debug)] struct Num {    value: i64, } impl From ...

Read More

HashMap in Rust Programming

Mukul Latiyan
Mukul Latiyan
Updated on 11-Mar-2026 705 Views

HashMap is an important data structure, as it allows us to store data in key-value pairs. In Rust, HashMap stores values by key.HashMap keys can be Boolean, Integer, strings or any other data type that implements the Eq and Hash traits.HashMaps can grow in size, and when the space becomes too excessive, they can also shrink themselves.We can create a HashMap in multiple ways, we can use either HashMap::with_capacity(uint) or HashMap::new().Following are the methods that HashMaps support:insert()get()remove()iter()ExampleLet’s see an example where we build a HashMap and use all these operations stated above.Consider the example shown below.use std::collections::HashMap; fn call(number: ...

Read More

Loop Keyword in Rust Programming

Mukul Latiyan
Mukul Latiyan
Updated on 11-Mar-2026 248 Views

Rust provides a loop keyword that allows us to run an infinite loop. The infinite loop indicated by the help of the loop keyword can be broken by the use of the break keyword. Also, we can exit an iteration and continue the infinite loop with the help of the continue keyword.ExampleConsider the example shown below −fn main() {    let mut count = 0u32;    println!("Infinite loop begins!!");    // Infinite loop    loop {       count += 1;       if count == 4 {          println!("four");          continue; ...

Read More
Showing 11241–11250 of 21,090 articles
Advertisements