Found 26504 Articles for Server Side Programming

Legal and illegal declaration and initializations in C

Bhanu Priya
Updated on 06-Mar-2021 07:02:53

2K+ Views

ProblemMention some of the legal and illegal declarations and initializations while doing C programming?Before discussing the legal and illegal statements let’s see how to declare and initialize the variables in C.Variable declarationFollowing is the syntax of variable declaration −SyntaxDatatype v1, v2, … vn;Where v1, v2, ...vn are names of the variables.For example, int sum;float a, b;Variable can be declared in two ways −local declarationglobal declarationThe ‘local declaration’ is declaring a variable inside the main block and its value is available within that block.The ‘global declaration’ is declaring a variable outside the main block and its value is available throughout the ... Read More

How to calculate sum of random numbers in between 0 to 100 using files in C Programming?

Bhanu Priya
Updated on 06-Mar-2021 16:35:57

2K+ Views

In this program, we are adding random numbers that are generated in between 0 and 100.After every runtime, the result of sum of random numbers is different, i.e., we get a different result for every execution.The logic we use to calculate the sum of random numbers in between 0 to 100 is −for(i = 0; i

How to display the data frame summary in vertical order in R?

Nizamuddin Siddiqui
Updated on 06-Mar-2021 05:29:23

409 Views

To display the data frame summary in vertical order, we can use lapply and cbind function along with the summary function. For example, if we have a data frame called df then the summary of df in vertical order can be found by using the below command −lapply(df, function(x) cbind(summary(x)))Example1Consider the below data frame −Live Demo> x1 x2 x3 x4 x5 df1 df1Output   x1 x2 x3 x4 x5 1   4  0  2  2  6 2   7  2  4  1  7 3   7  2  3  3  6 4   4  0  4  5  2 5   5  2 ... Read More

How to select rows of an R data frame that are non-NA?

Nizamuddin Siddiqui
Updated on 06-Mar-2021 05:27:42

10K+ Views

To select rows of an R data frame that are non-Na, we can use complete.cases function with single square brackets. For example, if we have a data frame called that contains some missing values (NA) then the selection of rows that are non-NA can be done by using the command df[complete.cases(df), ].Example1Consider the below data frame −Live Demo> x1 x2 x3 df1 df1Output   x1 x2 x3 1   1 NA NA 2  NA  5  3 3   1  5 NA 4   1 NA NA 5  NA  5 NA 6  NA  5  3 7  NA  5 NA 8   1 ... Read More

How to create stacked plot with density using ggplot2 in R?

Nizamuddin Siddiqui
Updated on 06-Mar-2021 05:25:12

441 Views

To create stacked plot with density using ggplot2, we can use geom_density function of ggplot2 package and position="stack". For example, if we have a data frame called df that contains two columns say x and y, where x is categorical and y is numerical then the stacked plot with density can be created by using the command −ggplot(df, aes(y, y=..density..))+geom_density(aes(fill=x), position="stack")ExampleConsider the below data frame −Live Demo> x y df dfOutput   x y 1  C 3 2  C 5 3  B 4 4  A 7 5  B 1 6  A 6 7  D 4 8  C 3 9  C 7 ... Read More

How to create a plot using ggplot2 by including values greater than a certain value in R?

Nizamuddin Siddiqui
Updated on 06-Mar-2021 05:24:47

3K+ Views

To create a plot using ggplot2 by excluding values greater than a certain value, we can use subsetting with single square brackets and which function. For example, if we have a data frame called df that contains two columns say x and y, then the point chart by including values of x that are greater than 0 can be created by using the command −ggplot(df[which(df$x>0), ], aes(x, y))+geom_point()ExampleConsider the below data frame −Live Demo> x y df dfOutput             x           y 1  -0.62160328  0.38477515 2   0.68287365 -1.56169067 3   0.75259774 ... Read More

How to make a plot title partially bold using ggplot2 in R?

Nizamuddin Siddiqui
Updated on 06-Mar-2021 05:24:05

4K+ Views

To make a plot title partially bold using ggplot2, we can use bquote function inside labs function and then changing the default font to bold using bold function as shown in the below examples. While using these functions we need to make sure that the title that we want to bold should be inside circular brackets appropriately.ExampleConsider the below data frame −Live Demo> x y df dfOutput             x           y 1  -0.62160328  0.38477515 2   0.68287365 -1.56169067 3   0.75259774  1.28849990 4   0.56688920 -0.17014225 5   1.22351113 -0.32446764 6  -1.54210099 ... Read More

How to calculate monthly average for time series object in R?

Nizamuddin Siddiqui
Updated on 06-Mar-2021 05:19:20

3K+ Views

To calculate monthly average for time series object, we can use tapply function with mean. For example, if we have a time series object called TimeData then the monthly average for this series can be found by using the command tapply(TimeData, cycle(TimeData), mean).Example1Consider the below time series object −Live Demo> Data1 Data1Output   Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 1  988 695 867 211 915 348 729 518 592 447 448 880 2  551 410 427 134 133 572 637 800 630 878 642 940 3  603 335 638 639 595 512 671 863 752 ... Read More

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

Nizamuddin Siddiqui
Updated on 06-Mar-2021 05:16:19

554 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 −Live Demo> x1 x2 x3 x4 df1 df1Output   x1 x2 x3 x4 1   3  4  4  5 2   6 10  3  3 3   6  5  2 ... Read More

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

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

306 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 −Live Demo> 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 ... Read More

Advertisements