Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to copy data from one column to a new column based on price range in R?

Hello, i have a dataset on shoes prices from amazon which look like this

Brand Available Price color
Nike Yes $50 Red
Nike Yes $40 – $50 RED
Adidas Yes $46 – $90 White
Puma Yes NAN White

My task is, if there are two prices like for second and third row then create a new row in table and put the second price, and if price is NAN then delete that column too.

I am new to R language and trying to solve this from 3 days, my task is to show mean prices of different brands in R with graphs like scatter plot graph, i am expecting the output like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Brand Available Price color
Nike Yes $50 Red
Nike Yes $40 RED
Adidas Yes $46 White
Nike Yes $50 RED
Adidas Yes $90 White

i tried different code but nothing is working can someone please help me with this.

This is my dataset

>Solution :

We could use separate_rows with the - separator and omit NAs:

library(dplyr)
library(tidyr)

df %>% 
  separate_rows(Price, sep=" - ") %>% 
  na.omit()
  Brand  Available Price color
  <chr>  <chr>     <chr> <chr>
1 Nike   Yes       $50   Red  
2 Nike   Yes       $40   RED  
3 Nike   Yes       $50   RED  
4 Adidas Yes       $46   White
5 Adidas Yes       $90   White
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading