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 in Data Analytics by Sophie may
• 9,870 points
32 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 by Zulaikha
• 870 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 in Data Analytics by anonymous
52 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,710 points
35 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,710 points
141 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 in Data Analytics by anonymous
• 32,260 points
122 views
0 votes
2 answers
0 votes
1 answer

Parallel programming In R using GPU

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

answered Feb 4 in Data Analytics by Tyrion anex
• 8,310 points
80 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 25 in Data Analytics by Sophie may
• 9,870 points
41 views
0 votes
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 in Data Analytics by Zulaikha
• 870 points
36 views
0 votes
1 answer

Probabilities in R programming

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

answered May 27 in Data Analytics by Zulaikha
• 870 points
98 views