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,330 points
12 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

This should work:

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

Related Questions In Data Analytics

0 votes
1 answer

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

Use the dplyr package that R provides: library(dplyr) df1 ...READ MORE

answered Apr 25 in Data Analytics by Sophie may
• 9,330 points
27 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,690 points
16 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,690 points
41 views
0 votes
1 answer

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

A variable name in R programming language ...READ MORE

answered Sep 7, 2018 in Data Analytics by zombie
• 3,690 points
65 views
0 votes
1 answer

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$symb ...READ MORE

answered Jan 11 in Data Analytics by Tyrion anex
• 8,280 points
62 views
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,280 points
45 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,330 points
18 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
• 640 points
13 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
• 640 points
16 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.