Programming Articles - Page 1371 of 3366

How to extract the split string elements in R?

Nizamuddin Siddiqui
Updated on 04-Mar-2021 08:10:17

3K+ Views

To split string vector elements, we can use strsplit function. And if we want to extract the string elements after splitting then double and single square brackets will be used. The double square bracket will extract the string vector element and the single square will extract the element after splitting. Check out the examples to understand how it works.Example1Live Demo> x1 x1Output[1] "Tutorialspoint is an E-learning platform" [2] "E-learning is important" [3] "It helps in learning and growing at a faster rate"Example> x1 x1Output[[1]] [1] "Tutorialspoint" "is" "an" "E-learning" [5] "platform" [[2]] [1] "E-learning" "is" "important" [[3]] [1] ... Read More

C Program to reverse a given number using Recursive function

Bhanu Priya
Updated on 15-Mar-2021 10:21:05

12K+ Views

"Recursive function" is something which calls itself again in the body of the function.For example, A function fact ( ), which computes the factorial of an integer ‘N’, which is the product of all whole numbers from 1 to N.fact ( ) with an argument of 1 (or) 0, the function returns 1. otherwise, it returns n*fact (n-1), this happens until ‘n’ equals 1.Fact (5) =5* fact (4)    =5*4*3* fact (3)    =5*4*3*2* fact (2)    =5*4*3*2*1 fact (1)    =5*4*3*2*1    = 120.ExampleFollowing is the C program for use of recursive function to reverse a number −#include main ... Read More

How to find the number of numerical columns in an R data frame?

Nizamuddin Siddiqui
Updated on 05-Mar-2021 05:36:54

1K+ Views

We know that a data frame can contain any type of columns such as numerical, character, logical, factor, etc. And if a data frame contains multiple type of columns then we might want to find the number of columns for each type or of one type say numerical. For this purpose, we can use select_if function of dplyr package along with the length function as shown in the below examples.Example1Consider the below data frame −Live Demo> x1 x2 x3 x4 df1 df1Output   x1      x2          x3    x4 1  a  -0.18404831  0.1082741 2 2  b ... Read More

What are different pointer operations and problems with pointers in C language?

Bhanu Priya
Updated on 15-Mar-2021 10:13:21

3K+ Views

A pointer is a variable whose value is the address of an another variable, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before using it to store any variable address.Consider the following statement −int qty = 179;The representation of the variable in memory is as follows −You can declare a pointer as follows −Int *p;It means ‘p’ is a pointer variable that holds the address of another integer variable.Address operator (&) is used to initialize a pointer variable.For Example −int qty = 175; int *p; p= &qty;To access the value of ... Read More

How to remove rows in an R data frame column that has duplicate values greater than or equal to a certain number of times?

Nizamuddin Siddiqui
Updated on 05-Mar-2021 05:39:16

354 Views

To remove rows from the data frame that duplicate values greater than a certain number of times, we can create a subset for rows having duplicate values less than the certain number of times. For this purpose, we first need to extract the rows and then subset the data frame with the particular column as shown in the below examples.Example1Consider the below data frame −Live Demo> x1 x2 df1 df1Output   x1 x2 1  0  0 2  0  0 3  1  0 4  0  1 5  0  0 6  1  1 7  0  1 8  1  1 9  1  2 10 ... Read More

State the difference between memcmp and memicmp functions in C language

Bhanu Priya
Updated on 15-Mar-2021 09:58:55

451 Views

Memcmp() and memicmp() compares first n bytes of two blocks of memory.memcmp() performs comparison as unsigned characters.memicmp() performs comparison as characters but, ignore upper case or lower case letters.Both functions return an integer value.Two memory buffers are equal (returns 0).First buffer is greater than second (returns >0).First buffer is less than second(returns0)       printf("buffer st1 is bigger than buffer st2");    if(x

How to convert an old data frame to new data frame in R?

Nizamuddin Siddiqui
Updated on 05-Mar-2021 05:42:17

548 Views

To convert an old data frame to a new data frame, we can simply set the new name. For example, if we have a data frame called df and want to convert it to a new one let’s say df_new then it can be done as df_new x1 x2 df1 df1Output x1 x2 1 8 6 2 4 9 3 3 2 4 3 5 5 7 4 6 4 8 7 8 6 8 12 12 9 8 6 10 ... Read More

How to change the position of missing values to the end of data frame in R?

Nizamuddin Siddiqui
Updated on 05-Mar-2021 05:48:05

165 Views

Most of the times we need to deal with missing values in data science projects and these missing values can be occurred at any position. We might want to change the position of these missing values and send them to the end of the columns in the data frame. This can be done with the help of lapply function as shown in the below examples.Example1Consider the below data frame −Live Demo> x1 x2 x3 df1 df1Output   x1 x2 x3 1  0  0  2 2  1  1  NA 3  1  NA 0 4  0  NA 2 5  1  NA 2 6 ... Read More

How to extract the first digit from a character column in an R data frame?

Nizamuddin Siddiqui
Updated on 05-Mar-2021 05:53:11

1K+ Views

If we have a character column in the data frame that contains string as well as numeric values and the first digit of the numeric values has some meaning that can help in data analysis then we can extract those first digits. For this purpose, we can use stri_extract_first function from stringi package.Example1Consider the below data frame −Live Demo> x1 y1 df1 df1Output x1 y1 1 1 HT14L 2 2 HT14L 3 3 HT23L 4 4 HT14L 5 5 HT32L 6 6 HT32L 7 ... Read More

How to swap two numbers without using the third or a temporary variable using C Programming?

Bhanu Priya
Updated on 15-Mar-2021 09:38:38

4K+ Views

With the help of addition and subtraction operations, we can swap two numbers from one memory location to another memory location.AlgorithmThe algorithm is explained below −STARTStep 1: Declare 2 variables x and y. Step 2: Read two numbers from keyboard. Step 3: Swap numbers. //Apply addition and subtraction operations to swap the numbers.    i. x=x+y    ii. y=x-y    iii. x=x-y Step 4: Print x and y values.ProgramFollowing is the C program which explains swapping of two numbers without using third variable or a temporary variable −#include int main(){    int x, y;    printf("enter x and y values:"); ... Read More

Advertisements