Nizamuddin Siddiqui

Nizamuddin Siddiqui

1,958 Articles Published

Articles by Nizamuddin Siddiqui

Page 157 of 196

Extract string vector elements up to a fixed number of characters in R.

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 02-Nov-2021 609 Views

To extract string vector elements up to a fixed number of characters in R, we can use substring function of base R.For Example, if we have a vector of strings say X that contains 100 string values and we want to find the first five character of each value then we can use the command as given below −substring(X,1,5)Example 1Following snippet creates a sample data frame −x1

Read More

How to create histogram for discrete column in an R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 02-Nov-2021 3K+ Views

To create histogram for discrete column in an R data frame, we can use geom_bar function of ggplot2 package and set the width to 1 also passing same column for x and y in aes.For example, if we have a data frame called df that contains a discrete column say x then the histogram for data in x can be created by using the below given command −ggplot(df,aes(x,x))+geom_bar(stat="identity",width=1)ExampleFollowing snippet creates a sample data frame −x

Read More

How to display X-axis tick marks as minimum and maximum only without their values using plotly in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 02-Nov-2021 564 Views

To display X-axis tick marks as minimum and maximum only without their values using plotly, we can use layout function of plot_ly package where we can pass the values for minimum and maximum using xaxis argument and the text using ticktext argument as shown in the below example.ExampleFollowing snippet creates a sample data frame −x

Read More

How to find the intersection of elements in a string vector in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 02-Nov-2021 835 Views

If we have a string vector that contains more than one element then there might exists some common values in all the elements. If we want to find those values then intersect function can be used along strsplit function and Reduce function.Check out the below Examples to understand how it can be done.Example 1>x1=c("Data science is an interdisciplinary field that uses scientific methods, processes, algorithms and systems to extract knowledge and insights from structured and unstructured data, and apply knowledge and actionable insights from data across a broad range of application domains.", "Data science is the domain of study that ...

Read More

How to find the sum of values based on two groups if missing values are present in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 02-Nov-2021 409 Views

To find the sum of values based on two groups if missing values are present, we can use group_by and summarise function of dplyr package.For example, if we have a data frame called df that contains a numerical column say Num and two grouping columns say Grp1 and Grp2 then, the sum of values in Num based on Grp1 and Grp2 if missing values are present in df can be found by using the below mentioned command −df%>%group_by(Grp1, Grp2)%>%summarise(Sum=sum(Num, na.rm=TRUE))Example 1Following snippet creates a sample data frame −grp1

Read More

How to deal with error "var(x) : Calling var(x) on a factor x is defunct." in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 02-Nov-2021 5K+ Views

The error “Calling var(x) on a factor x is defunct” occurs when we try to apply a numerical function on factor data.For example, if we have a factor column in a data frame then applying numerical functions on that column would result in the above error. To deal with this problem, we can use as.numeric function along with the numerical function as shown in the below examples.Example 1Following snippet creates a sample data frame −x

Read More

Roll up R data frame columns for summation by group if missing values exist in the data frame.

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 02-Nov-2021 546 Views

The summation of column values if missing values exist in the R data frame can be found with the help of summarise_each function of dplyr package where we can remove missing values by setting na.rm argument to TRUE.Since, we we will have groups in the data frame hence group_by function of the same package will help the summarise_each function to perform the summation by group. Check out the below Examples to understand how it works.Example 1Following snippet creates a sample data frame −Grp

Read More

How to create a base R plot without axes but keeping the frame of the plot?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 02-Nov-2021 454 Views

To create a base R plot without axes but keeping the frame of the plot, we can set axes argument to FALSE and frame.plot argument to TRUE.For example, if we have a vector called V and we want to create a plot of V without axes but with the frame of the plot then, we can use the command given below −plot(V,axes=FALSE,frame.plot=TRUE)Check out the below example to understand how it works.ExampleConsider the following snippet −x

Read More

How to find the variance of frequency data in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 02-Nov-2021 579 Views

If we have frequency data then we first need to find the total data or complete data by repeating the values up to the frequency corresponding to each value after that we can apply var function on this complete data.For Example, if we have a data frame called df that contains two columns say X and Frequency then we can find the total data by using the command given below −Total_data

Read More

How to find the autocorrelation values from ACF plot in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 02-Nov-2021 4K+ Views

The autocorrelation plot or ACF plot is a display of serial correlation in data that changes over time. The ACF plot can be easily created by using acf function.For example, if we have a vector called V then we can create its autocorrelation plot by using the command acf(V). If we want to extract autocorrelation values then we would need to save the plot values in an object by using the below command. This will not create the plot.Autocorrelation_x

Read More
Showing 1561–1570 of 1,958 articles
« Prev 1 155 156 157 158 159 196 Next »
Advertisements