I'm trying to remove the characters in even rows of a specific column.
My dataset looks like this:
name | value |
---|---|
apple | 3 |
apple | (0,1) |
banana | 6 |
banana | (-2,6) |
cherry | 3 |
cherry | (4,6) |
And this is what I'm expecting:
name | value |
---|---|
apple | 3 |
(0,1) | |
banana | 6 |
(-2,6) | |
cherry | 3 |
(4,6) |
Thank you!
CodePudding user response:
You may try:
df$name[!c(TRUE, FALSE)] <- ""
This will assign empty string to even rows of the name
column.
CodePudding user response:
If the goal is to remove all the name
values which are repeated, you may use duplicated
.
df$name[duplicated(df$name)] <- ''
df
# name value
#1 apple 3
#2 (0,1)
#3 banana 6
#4 (-2,6)
#5 cherry 3
#6 (4,6)