[R] How to add specific column to data.set?

R. Michael Weylandt michael.weylandt at gmail.com
Tue Apr 17 18:57:57 CEST 2012


Do you have lists or something like a data.frame? Your printout
suggests you don't actually have a list. (well, data.frames really are
lists but let's just not talk about that)

Perhaps %in% is what you are looking for...

EU <- c("UK","FR","DE") # Yes, I know there are more....

countries <- c("US","CH","UK", "CA", "MX", "FR", "DE")

countries %in% EU

or more to your question

cbind(countries, countries %in% EU)

or

data.frame(Country = countries, EU.Member = countries %in% EU)

Michael

On Tue, Apr 17, 2012 at 12:40 PM, phillip03 <phillipbrigham at hotmail.com> wrote:
> Hi
> I have a data.set with 7 lists, with over 7000 observations in each list. to
> of the lists contain country names.
> like:
> aus   dnk
> fra   aus
> usa  aut
> itl    usa
> .
> .
> .
> etc.
>
> My dilemma is that I want to add an extra column/list to my data.set. If the
> countries are both european it should be assigned 1 or true AND if one or
> both the countries are non-european it should be assigned 0 or false.
>
> Please et me know if you dont understand my dilemma.
>
> Thanks
>
> --
> View this message in context: http://r.789695.n4.nabble.com/How-to-add-specific-column-to-data-set-tp4565341p4565341.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list