Hello
I have the following dataframe
df <- data.frame(
Project=c("Abaco","Abaco","Abac","Abaco","Abaco","Abaco",
"Abaco","Adaptclone","Adaptclone","Adaptclone","Adaptclone","Adaptclone",
"Adaptclone","Adopt","Adopt","Adopt"),
Country=c("Zimbabwe","Burkina Faso","South Africa","Madagascar","Tanzania",
"Mali","Mozambique","Madagascar","Ghana","Nigeria","Kenya","Burkina Faso",
"South Africa","Tanzania","Kenya","Ethiopia" ),
Iso=c("ZW","BF","ZA","MG","TZ","ML","MZ","MG","GH","NG","KE","BF",
"ZA","TZ","KE","ET"))
I would like to build a other dataframe with name Country
where column 1 is country,
the column 2 is number of project (in the country)
the column 3 is the code Iso (wich correspond with the country : Ex ZW
is ISO of Zimbabwe)
Pays PaysIso NbrProj
Zimbabwe ZW 1
Burkina Faso BF 2
I know associate Country and Number of projets but how associate Iso
Any idea ?
Thank you for your help
Michel ARNAUD
Charg? de mission aupr?s du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31
Hello,
Try the following.
aggregate(Project ~ Country + Iso, data = df, FUN = length)
Hope this helps,
Rui Barradas
Em 19-06-2013 15:23, Arnaud Michel escreveu:
Hello
I have the following dataframe
df <- data.frame(
Project=c("Abaco","Abaco","Abac","Abaco","Abaco","Abaco",
"Abaco","Adaptclone","Adaptclone","Adaptclone","Adaptclone","Adaptclone",
"Adaptclone","Adopt","Adopt","Adopt"),
Country=c("Zimbabwe","Burkina Faso","South Africa","Madagascar","Tanzania",
"Mali","Mozambique","Madagascar","Ghana","Nigeria","Kenya","Burkina Faso",
"South Africa","Tanzania","Kenya","Ethiopia" ),
Iso=c("ZW","BF","ZA","MG","TZ","ML","MZ","MG","GH","NG","KE","BF",
"ZA","TZ","KE","ET"))
I would like to build a other dataframe with name Country
where column 1 is country,
the column 2 is number of project (in the country)
the column 3 is the code Iso (wich correspond with the country : Ex ZW
is ISO of Zimbabwe)
Pays PaysIso NbrProj
Zimbabwe ZW 1
Burkina Faso BF 2
I know associate Country and Number of projets but how associate Iso
Any idea ?
Thank you for your help
Hi,
May be this helps:
library(plyr)
?ddply(df,.(Country,Iso),summarize,NbrProj=length(Project))
#??????? Country Iso NbrProj
#1? Burkina Faso? BF?????? 2
#2????? Ethiopia? ET?????? 1
#3???????? Ghana? GH?????? 1
#4???????? Kenya? KE?????? 2
#5??? Madagascar? MG?????? 2
#6????????? Mali? ML?????? 1
#7??? Mozambique? MZ?????? 1
#8?????? Nigeria? NG?????? 1
#9? South Africa? ZA?????? 2
#10???? Tanzania? TZ?????? 2
#11???? Zimbabwe? ZW?????? 1
A.K.
A.K.
----- Original Message -----
From: Arnaud Michel <michel.arnaud at cirad.fr>
To: r-help at r-project.org
Cc:
Sent: Wednesday, June 19, 2013 10:23 AM
Subject: [R] to build a data.frame
Hello
I have the following dataframe
df <- data.frame(
Project=c("Abaco","Abaco","Abac","Abaco","Abaco","Abaco",
"Abaco","Adaptclone","Adaptclone","Adaptclone","Adaptclone","Adaptclone",
"Adaptclone","Adopt","Adopt","Adopt"),
Country=c("Zimbabwe","Burkina Faso","South Africa","Madagascar","Tanzania",
"Mali","Mozambique","Madagascar","Ghana","Nigeria","Kenya","Burkina Faso",
? "South Africa","Tanzania","Kenya","Ethiopia" ),
Iso=c("ZW","BF","ZA","MG","TZ","ML","MZ","MG","GH","NG","KE","BF",
? "ZA","TZ","KE","ET"))
I would like to build a other dataframe with name Country
where column 1 is country,
the column 2 is number of project (in the country)
the column 3 is the code Iso (wich correspond with the country : Ex ZW
is ISO of Zimbabwe)
? ? ? Pays? ? ? ? PaysIso? NbrProj
? ? Zimbabwe? ? ? ZW? ? ? 1
? Burkina Faso? ? BF? ? ? ? 2
I know associate Country and Number of projets but how associate Iso
Any idea ?
Thank you for your help
Michel ARNAUD
Charg? de mission aupr?s du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31
______________________________________________
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.
Country Iso Project
1 Burkina Faso BF 2
2 Ethiopia ET 1
3 Ghana GH 1
4 Kenya KE 2
5 Madagascar MG 2
6 Mali ML 1
7 Mozambique MZ 1
8 Nigeria NG 1
9 Tanzania TZ 2
10 South Africa ZA 2
11 Zimbabwe ZW 1
Or if you prefer left-aligned:
Country Iso Project
1 Burkina Faso BF 2
2 Ethiopia ET 1
3 Ghana GH 1
4 Kenya KE 2
5 Madagascar MG 2
6 Mali ML 1
7 Mozambique MZ 1
8 Nigeria NG 1
9 Tanzania TZ 2
10 South Africa ZA 2
11 Zimbabwe ZW 1
-------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77840-4352
-----Original Message-----
From: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-project.org] On Behalf Of Arnaud Michel
Sent: Wednesday, June 19, 2013 9:23 AM
To: r-help at r-project.org
Subject: [R] to build a data.frame
Hello
I have the following dataframe
df <- data.frame(
Project=c("Abaco","Abaco","Abac","Abaco","Abaco","Abaco",
"Abaco","Adaptclone","Adaptclone","Adaptclone","Adaptclone","Adaptcl
one",
"Adaptclone","Adopt","Adopt","Adopt"),
Country=c("Zimbabwe","Burkina Faso","South
Africa","Madagascar","Tanzania",
"Mali","Mozambique","Madagascar","Ghana","Nigeria","Kenya","Burkina
Faso",
"South Africa","Tanzania","Kenya","Ethiopia" ),
Iso=c("ZW","BF","ZA","MG","TZ","ML","MZ","MG","GH","NG","KE","BF",
"ZA","TZ","KE","ET"))
I would like to build a other dataframe with name Country
where column 1 is country,
the column 2 is number of project (in the country)
the column 3 is the code Iso (wich correspond with the country : Ex
ZW
is ISO of Zimbabwe)
Pays PaysIso NbrProj
Zimbabwe ZW 1
Burkina Faso BF 2
I know associate Country and Number of projets but how associate Iso
Any idea ?
Thank you for your help
Michel ARNAUD
Charg? de mission aupr?s du DRH
DGDRD-Drh - TA 174/04
Av Agropolis 34398 Montpellier cedex 5
tel : 04.67.61.75.38
fax : 04.67.61.57.87
port: 06.47.43.55.31
______________________________________________
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.