[R] Generation of labels for 2 factors

Liaw, Andy andy_liaw at merck.com
Tue Sep 30 18:27:36 CEST 2003


Not sure exactly what you want, but try:

  countrySector <- factor(paste(df$country, df$sector, sep=":"))

where df is the data frame.  This creates a factor for the combination.  If
you want numeric code, just coerce with as.numeric().

HTH,
Andy

> -----Original Message-----
> From: Xavier Fernández i Marín [mailto:xavier.fim at eresmas.net] 
> Sent: Tuesday, September 30, 2003 11:42 AM
> To: r-help at stat.math.ethz.ch
> Subject: [R] Generation of labels for 2 factors
> 
> 
> Hello,
> 
> I have a data set with 10 countries, 10 sectors of public 
> policy and 15 years 
> like
> country	sector	year
> a	aa	1980
> a	aa	1981
> ...
> a	bb	1980
> a	bb	1981
> ...
> b	aa	1980
> b	aa	1981
> ...
> b	bb	1980
> b	bb	1981
> ....
> 
> with 1500 observations.
> 
> My cases are the couple country/sector. So, I want to have 
> 100 cases over 15 
> years. (both country and sector are factors)
> 
> I want to assign to each case a label (e.i. country 'a' + 
> sector 'aa' have 
> value '1', country 'a' + sector 'b' have value 2...) and I 
> have been trying 
> differents ways, but I can't.
> 
> 
> Is there a function to do it directly or I have to write a function? 
> 
> Thank you,
> 
> 
> Xavier
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list 
> https://www.stat.math.ethz.ch/mailman/listinfo> /r-help
>




More information about the R-help mailing list