Changing variable values using R programming

0 votes

I've imported a CSV file and I want to change the variable value for symbol column. If the value is "ABCD.BO" then "Stock_T". If the value is "XYZ.BO" then "Stock_Y". I tried to fix it but I am getting a warning message and I checked the dataframe contains "NA" after changing.

df$symbol[df$symbol == "ABCD.BO"] <- "Stock_T"
df$symbol[df$symbol == "XYZ.BO"] <- "Stock_Y"

Warning message:
In `[<-.factor`(`*tmp*`, df$symbol == "ABCD.BO",  :
  invalid factor level, NA generated
May 27, 2019 in Data Analytics by Sophie may
• 10,620 points
921 views

1 answer to this question.

0 votes

This should work:

df$symbol <- as.character(df$symbol)
df$symbol[df$symbol == "ABCD.BO"] <-"Stock_T"
answered May 27, 2019 by Zulaikha
• 910 points

Related Questions In Data Analytics

0 votes
2 answers

How can I group a set of values by column using R programming?

Try this , Employee %>% group_by(EmpID) %>% mutate(SumSalary ...READ MORE

answered Aug 14, 2019 in Data Analytics by anonymous
813 views
0 votes
1 answer

How can I print string and variable contents on the same line using R?

There are two options for doing so.  You ...READ MORE

answered May 9, 2018 in Data Analytics by zombie
• 3,790 points
1,877 views
0 votes
1 answer

Changing R default library path using .libPaths ?

You should try using one library but ...READ MORE

answered May 30, 2018 in Data Analytics by zombie
• 3,790 points
1,499 views
0 votes
2 answers

What are the rules to define a variable name in R programming language?

The same rules almost follow for all ...READ MORE

answered Aug 26, 2019 in Data Analytics by anonymous
• 33,030 points
15,123 views
+1 vote
3 answers

How to change the value of a variable using R programming in a data frame?

Try this: df$symbol <- as.character(df$symbol) df$symbol[df$sym ...READ MORE

answered Jan 11, 2019 in Data Analytics by Tyrion anex
• 8,700 points
35,824 views
+1 vote
1 answer

Parallel programming In R using GPU

Check out the CRAN Task View on High-Performance ...READ MORE

answered Feb 4, 2019 in Data Analytics by Tyrion anex
• 8,700 points
1,398 views
0 votes
1 answer

R programming: Naming the output file using a variable

Use the paste command: write.csv(max.hsi, paste0("Index_", i,".csv ...READ MORE

answered Mar 26, 2019 in Data Analytics by Sophie may
• 10,620 points
6,520 views
+1 vote
1 answer
0 votes
1 answer

Scraping columns from a website by using R Programming

Here's an example, use the html_table : library(rvest) library(dplyr) url <- ...READ MORE

answered Jun 7, 2019 in Data Analytics by Zulaikha
• 910 points
691 views
0 votes
1 answer

Probabilities in R programming

This should work: poker_face <- replicate(1000, sample(poker, size ...READ MORE

answered May 27, 2019 in Data Analytics by Zulaikha
• 910 points
1,687 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP