خرید بک لینک

Vote count: 0

I have a data frame (called honey) that looks like:

Importer    year    tons    USD
Japan       2010    523     776
Thailand    2010    1095    975
Singapore   2010    1       2
...

I want to parse out the distinct countries, and add one to the list in my code.

unique(honey$Importer)

Retus the expected result; a list of 8 countries:

[1] Japan                    Thailand                
[3] Singapore                China                   
[5] Malaysia                 United States of America
[7] Canada                   Taipei, Chinese         
8 Levels: Canada China Japan Malaysia Singapore ... United States of America

But when I try to add one, like so:

c(unique(honey$Importer),'Myanmar')

I get:

[1] "3"       "7"       "5"       "2"       "4"       "8"      
[7] "1"       "6"       "Myanmar"

What makes this weird - and hard for me to understand - is that if I choose a different column, I get exactly what I'd expect:

c(unique(honey$year),'Myanmar')
[1] "2010"    "2011"    "2012"    "2013"    "2014"    "2015"   
[7] "Myanmar"

Can anyone tell me what I'm doing wrong?

asked 4 mins ago

1 Answer

Vote count: 0

We can convert to character as year is factor class.

c(as.character(unique(honey$year)),'Myanmar')

answered 3 mins ago

برچسب: نویسنده: استخدام کار تاريخ: شنبه 11 ارديبهشت 1395 ساعت: 23:42

صفحه بندی