[R] Unique in DataFrame

MSousa ricardosousa2000 at clix.pt
Tue Mar 20 15:16:04 CET 2012


Hello,

    I have little doubt, and I do not think that the way I solve the problem
is the best way to do it. 
The following is a small dataset


x<-data.frame(city="Barcelona",sales=253639)
x<-rbind(x,data.frame(city="Madrid",sales=223455))
x<-rbind(x,data.frame(city="Lisbon",sales=273633))
x<-rbind(x,data.frame(city="Madrid",sales=266535))
x<-rbind(x,data.frame(city="Barcelona",sales=258369))
x<-rbind(x,data.frame(city="Lisbon",sales=273633))
x<-rbind(x,data.frame(city="Barcelona",sales=22579))
x<-rbind(x,data.frame(city="Lisbon",sales=26333))
x<-rbind(x,data.frame(city="Barcelona",sales=253639))

x$num<-as.numeric(as.numeric(factor(x$city)))
View(x)

my problem and my doubts start here, I'm trying to create a list of cities
and the code that was assigned in.
x$num<-as.numeric(as.numeric(factor(x$city)))

here seems to work fine, but the largest dataset repeats some values ​​and
hiding others, this is the correct way to present unique values ​​in a
column, and view the contents with other columns

rescity<-x[unique(x$city),c(3,1)]
rescity

   Thanks


--
View this message in context: http://r.789695.n4.nabble.com/Unique-in-DataFrame-tp4488943p4488943.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list