R Replace Values in Data Frame Conditionally (4 Examples) | Exchange Value in Column & Entire Matrix

preview_player
Показать описание
R code of this video:

num2 = 3:7,
char = letters[1:5],
fac = c("gr1", "gr2", "gr1", "gr3", "gr2"))

data$num1[data$num1 == 1] <- 99 # Replace 1 by 99

data$char[data$char == "b"] <- "XXX" # Replace b by XXX

data$fac[data$fac == "gr1"] <- "new_group" # Replace gr1 by new_group

data[data == 3] <- 777 # Replace all values

Follow me on Social Media:
Рекомендации по теме
Комментарии
Автор

Liked it! Concept explained nicely with easy examples and simple manner to help understand! Keep it up!

vijayarjunwadkar
Автор

thanks you. i want to know, how to replace multiple values in the same column with a corresponding list of values with a single click

ambroiseyeboua
Автор

Hello! Thanks for this video, I finally understood why a bit of the code didn't work for me! I have a question that I don't know if there is even an answer (at least I can't find it anywhere). I want to do this replacement but with two conditions, I don't get any error but the replacement isn't being done. Plus, I already transformed both variables into chr.
== "NA" & credit_data$lenght == "NA"] <- "0"
Thank you!

danielarotaru
Автор

Do you have a video that explains how to replace a value in one column, given another value in a different column? For instance, my dataframe named data has two columns, NAME and OCCUPATION. In pseudo-code, I want something that does this: if data$NAME = "Marie", then data$occupation = "Statistician" but only for that same row. Optimally, this would be in basic R.

ProfBoggs
Автор

Thank you for nice video. Kindly mention how to change the whole data frame with some logical condotion.

ashisranjanudgata
Автор

How to change/replace/impute 04-04-2020 to 04/04/2020 in date column ? if Date column is character column

CoachPegasus
Автор

I need your help, actually I have data frame in which duplicate value, I want to add new column and show if any value comes two times then I want againt both result come 2, 2 and if repeat three times then it comes 3 againt all repeated values which comes thrice.

SudhirKumar-rygk
Автор

team code
<chr> <chr>
1 QATAR QA
2 ENGLAND NA
3 SENEGAL SN
4 UNITED STATES US
5 ARGENTINA AR
6 DENMARK DK
7 ENGLAND NA
8 WALES NA
9 WALES NA

Given the data frame above, i want to convert the NA for ENGLAND and WALES to their code, EN and WL, respectively while keeping the codes for the other countries unchanged. How do i write the code in R. Thanks

jamesleleji
Автор

Hello Sir your videos are really helpful while solving exercise but I really need your help in one problem I came across data science in R book.
Q. For the job field, combine the jobs with less than 5% of the records into a field called other.
Above question is from bank_marketing_training data set of 26874 obs of 21 variables, in that job is one of them.How to compute in R I didn't get how to write in R and get it executed.

abhijeetjahagirdar