Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
375 views
in Technique[技术] by (71.8m points)

r - How to remove duplicate values in specific column without removing related row

Want to remove duplicate values in specific column without deleting the rows related with duplicate column values as below example:

Input
-----
    Date    Market      Quantity
4/2/2018    Indonesia   1000
4/2/2018    Australia   500
4/2/2018    India       300
4/2/2018    USA         500
4/2/2018    Germany     200
5/2/2018    India       400
5/2/2018    Japan       400
5/2/2018    Russia      457
6/2/2018    Austria     260
6/2/2018    Swiss       700
6/2/2018    USA         1200
6/2/2018    Indonesia   400


output
------
    Date    Market      Quantity
4/2/2018    Indonesia   1000
            Australia   500
            India       300
            USA         500
            Germany     200
5/2/2018    India       400
            Japan       400
            Russia      457
6/2/2018    Austria     260
            Swiss       700
            USA         1200
            Indonesia   400

And if possible , how to plot a graph(bar/column) for same output(something like given)? Sample Graph

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I would add this to comments but I don't have rights yet...

I don't think you actually want to change the data, but as a few mentioned in the comments there are easy ways to do that.

If you're just trying to show the multi-dimensional data in plotly and you're just not familiar with the library syntax try the code below...

df <- data.frame(Date = c('2018/04/02','2018/04/02','2018/04/02','2018/04/02','2018/04/02','2018/05/02','2018/05/02','2018/05/02','2018/06/02','2018/06/02','2018/06/02','2018/06/02'),
  Market = c('Indonesia','Australia','India','USA','Germany','India','Japan','Russia','Austria','Swiss','USA','Indonesia'),
  Quantity = c(1000,500,300,500,200,400,400,457,260,700,1200,400),
  stringsAsFactors = F)

plotly::ggplotly(
      ggplot2::ggplot(df, ggplot2::aes(x=Market, y=Quantity)) +
        ggplot2::geom_col(ggplot2::aes(fill=Market))+
        ggplot2::facet_grid(~Date,scale='free_x') +
        ggthemes::theme_tufte()
      )

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...