
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 33676 Articles for Programming

610 Views
Sometimes we don’t require the whole string to proceed with the analysis, especially when it complicates the analysis or making no sense. In such type of situations, the part of string which we feel that is not necessary can be removed from the complete string. For example, suppose we have a string ID:00001-1 but we don’t want -1 in this string then we can remove it and this can be done with the help of gsub function.Example> x1 gsub("\-.*", "", x1) [1] "ID:00001" "ID:00100" "ID:00201" "ID:014700" "ID:12045" "ID:00012" "ID:10078" > x2 gsub("\/.*", "", x2) [1] "ID:00001" "ID:00100" "ID:00201" "ID:014700" "ID:12045" ... Read More

514 Views
We often see mistakes in data collection processes and these mistakes might lead to incorrect results of the research. When the data is collected with mistakes, it makes the job of analyst difficult. One of the situations, that shows the data has mistakes is getting strings in place of numerical values. Therefore, we need to convert these strings to NA in R so that we can proceed with our intended analysis.ExampleConsider the below data frame −> x1 x2 df df x1 x2 1 1 67 2 3 67 3 6 67 4 7 67 5 5 XYZ 6 2 XYZ ... Read More

163 Views
The combination of two vectors is used for many purposes such as performing two-way ANOVA, presenting data table, or making visual representation of the data. The combinations can be created with many special characters in R by using paste and rep function.ExampleConsider the below vectors Class and Names.> Class Class [1] "Stats" "Maths" "Chem" "Physics" "O-R" > Names Names [1] 101 102 103 104 105Suppose we want to combine Class and Names in a way that the new vector contains Stats|101, Stats|102, and so on. Also, we want to do the same with different special characters.We can do this by ... Read More

591 Views
Data can be supplied to us in any form but it is possible that it is not the appropriate one that should be used for analysis. Sometimes data is recorded in a data frame but we might need it as a vector. In such type of situation, we have to change the values of our data frame in a vector. This can be done by reading the data frame values by reading them as.vector after transposing the data frame with t.ExampleConsider the below data frame −> x1 x2 x3 df df x1 x2 x3 1 1 1 5 2 ... Read More

2K+ Views
This error occurs because $ operator is not designed to access vector elements. If we use $ operator to access the vector elements then R does not understand it and consider it invalid, therefore, we must be very careful about where we should use $ operator. It happens when we give a name to our elements and start thinking that we can treat them as data frame columns which is a wrong approach. To access the vector elements, we should use single square brackets.ExampleConsider the below vector −> set.seed(1) > x1 x1 [1] 9 4 7 1 2 7 2 ... Read More

380 Views
While writing the string vectors, we get them in a single line but we might want to represent strings in different lines especially in cases where each of the value of the string vector has a different meaning. This is helpful to the programmer as well as to any other reader. We can change the single line to multiple new lines using writeLines function in R.ExampleReading with single line −> String1 String1 [1] "Covid-19" "2020" "Lockdown" "Quarantine" "Life Changing"Reading the same vector with new lines −> String1 String2 writeLines(String2) Tutorialspoint SIMPLY EASY LEARNING You are browsing the best resource for ... Read More

3K+ Views
An NA value in R represents “Not Available” that means missing value. If a vector has even one NA value then the calculations for that vector becomes a little difficult because we will either have to remove that NA, replace it or neglect it during the calculations. To do any of these things, we will have to make some changes in our codes therefore, it is better to check whether a vector contain an NA or not before doing anything. This can be done with the help of any function in conjunction with is.na.Example> x1 x1 [1] 1 2 3 ... Read More

279 Views
A column’s position in an R data frame is crucial specially when we are dealing with a large data set. As the first column appears first, it becomes necessary that we should have columns of the data frame in an order that helps us to look at the important columns easily. For this purpose, we might want to change the position of columns. To change the position of a column to first position we can use single square brackets.ExampleConsider the below data frame −> set.seed(99) > x1 x2 x3 x4 x5 x6 df df x1 x2 x3 x4 x5 x6 ... Read More

10K+ Views
Random selection of elements from a R vector ensures the unbiased selection because while doing the random selection, each of the elements of the vector gets an equal probability of being selected by the random selection procedure specifically the simple random sampling selection procedure. To select, one or more elements randomly from an R vector, we can use sample function.Example> x1 x1 [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 [26] 26 27 28 29 30 31 32 33 34 35 36 ... Read More

556 Views
Sometimes, the column value of a particular column has some relation with another column and we might need to change the value of that particular column based on some conditions. We need to make this change to check how the change in the values of a column can make an impact on the relationship between the two columns under consideration. In R, we can use single square brackets to make the changes in the column values.ExampleConsider the below data frame −> set.seed(1) > x1 x2 x3 df df x1 x2 x3 1 4 4 4.462839 2 4 1 3.941181 3 ... Read More