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,610 points
702 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
591 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,656 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,269 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
14,490 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,234 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,210 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,610 points
5,745 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
538 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,393 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