how to rename a row in r studio, for example
view(mydata)
a | b | c |
red | 1 | 4 |
yellow | 2 | 4 |
white* | 5 |
6 |
black | 0 | 6 |
pink | 6 | 3 |
purple | 10 | 5 |
I want to rename the row 4, white* to white. I need to remove the "*"
also I want to add a new column, with repetition values for ex.
new column |
1 |
2 |
3 |
1 |
2 3 |
please help, how can I write in R-program
STEP - BY - STEP PROCESS
(1.) Make a data frame ==> 'mydata'
a <- c('red', 'yellow', 'white*', 'black', 'pink', 'purple')
b <- as.numeric(c(1, 2, 5, 0, 6, 10))
mydata <- data.frame(a, b)
mydata
(2.) Remove "*" from white*
mydata$a <- gsub("[*]", "", mydata$a)
mydata
(3.) A new column with repetition values
new_col <- c(rep(1:3,length.out=nrow(mydata)))
mydata['new_col'] <- new_col
mydata
NOTE: All codes above in the R language. Please use R-studio for better understanding.
Thumbs Up Please !!!
Get Answers For Free
Most questions answered within 1 hours.