Removing duplicated column characters of dataset in r

本秂侑毒 提交于 2020-05-15 19:26:25

问题


I am new to r and I have problems with removing duplicated characters.

Here is my code:

library(RCurl)
x <- getURL("https://raw.githubusercontent.com/eparker12/nCoV_tracker/master/input_data/coronavirus.csv")
y <- read.csv(text = x)
z <- duplicated(y$jhuID)

I tried something like z <- ... but it did not work. For the column jhuID in the dataframe it is the class character but there are many name of countries that repeat multiple times and my goal is to delete those duplicated name of country and make sure that it remain only one time with the same class character

For example if I view data by y$jhuID, I will see all the names of the country that appear multiple time. I want new dataframe for example z when I view z$jhulD I will see the name of country appear only one time each.

Any help for this would be much appreciated!! Thanks in advance


回答1:


An option with h distinct and arrange

library(dplyr)
y %>%
     distinct(jhu_ID, .keep_all = TRUE) %>%
     arrange(jhu_ID)


来源:https://stackoverflow.com/questions/61806711/removing-duplicated-column-characters-of-dataset-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!