[R] Information Frequency problem calculation
David Carlson
dcarlson at tamu.edu
Mon Oct 7 20:12:14 CEST 2013
If you want a symmetric table, try this:
> a<- read.table(text="Name1 Name2 category
+ mauro francesco E234
+ luca giuseppe E5578
+ luca franco E5569
+ maria luca E4556",sep="",header=TRUE,stringsAsFactors=FALSE)
> names <- sort(unique(c(a$Name1, a$Name2)))
> a$Name1 <- factor(a$Name1, names)
> a$Name2 <- factor(a$Name2, names)
> xtabs(~Name1+Name2, a)
Name2
Name1 francesco franco giuseppe luca maria mauro
francesco 0 0 0 0 0 0
franco 0 0 0 0 0 0
giuseppe 0 0 0 0 0 0
luca 0 1 1 0 0 0
maria 0 0 0 1 0 0
mauro 1 0 0 0 0 0
-------------------------------------
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 arun
Sent: Monday, October 7, 2013 11:45 AM
To: jarod_v6 at libero.it
Cc: R help
Subject: Re: [R] Information Frequency problem calculation
Hi,
Not sure what your expected output would be:
a<- read.table(text="Name1 Name2 category
mauro francesco E234
luca giuseppe E5578
luca franco E5569
maria luca E4556",sep="",header=TRUE,stringsAsFactors=FALSE)
sapply(seq_len(nrow(a)),function(i) sum(a[,2] %in% a[i,1]))
#[1] 0 1 1 0
A.K.
----- Original Message -----
From: "jarod_v6 at libero.it" <jarod_v6 at libero.it>
To: r-help at r-project.org
Cc:
Sent: Monday, October 7, 2013 12:09 PM
Subject: [R] Information Frequency problem calculation
Dear All,
I Have a dataframe like that:
Name1 Name2 category
mauro francesco E234
luca giuseppe E5578
luca franco E5569
maria luca E4556
...
I would like to calculate the frequency of many time in my data
I found in
the list name:
a<-read.table("pippo.csv",header=T,sep="\t")
name1<-as.character(a[,1])
name2<-as.character(a[,2])
category<-as.character(a[,3])
for(i in 1:lenght(name1)){
re <-which(name1 == name2)
}
So how can create a table of frequncy of many times I found a
name in column
one respect to the second ?
Thanks in advance for your help!
M.
______________________________________________
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.
______________________________________________
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