I have two datasets, the first has this shape (each word is a column) Name address phone .. .. The second one has the following shape Name request I need a contingency table with for example phone and request. The people registered in these datasets are present in both datasets, BUT in the first every record is a person, so every person is counted once and is 1 row, in the second every row is a request, so if a person has requested 1 thing this person is present only once, but is the person has requested 3 things, this person we'll be present 3 times. ?? I now that to use access could be the solution, but in this moment the computer expert give me data only as .xls/.csv data. This creates the possibility of two different cross tab, I really need both, the first has as total count the number of people The second one has as total count the number of request -- View this message in context: http://r.789695.n4.nabble.com/Interweaving-of-two-datasets-tp4608505.html Sent from the R help mailing list archive at Nabble.com.
Hello, lunarossa wrote> > I have two datasets, the first has this shape (each word is a column) > Name address phone .. .. > > The second one has the following shape > Name request > > I need a contingency table with for example phone and request. > > > The people registered in these datasets are present in both datasets, BUT > in the first every record is a person, so every person is counted once and > is 1 row, in the second every row is a request, so if a person has > requested 1 thing this person is present only once, but is the person has > requested 3 things, this person we'll be present 3 times. ?? > > I now that to use access could be the solution, but in this moment the > computer expert give me data only as .xls/.csv data. > > This creates the possibility of two different cross tab, I really need > both, > the first has as total count the number of people > The second one has as total count the number of request >Try ?merge set.seed(1) df1 <- data.frame(Name=LETTERS[1:5], Phone=1:5) df2 <- data.frame(Name=sample(LETTERS[1:5], 20, TRUE), Request=sample(letters[1:3], 20, TRUE)) joined <- merge(df1, df2) with(joined, table(Name, Request)) Also, I hope this is what you want, it corresponds to your description but there's no "reproducible example (posting-guide)". Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/Interweaving-of-two-datasets-tp4608505p4608740.html Sent from the R help mailing list archive at Nabble.com.
it doesn't work. Find attached what I need explained in xls. Thank you very very much! http://r.789695.n4.nabble.com/file/n4622912/interweaving_of_2_datasets.xls interweaving_of_2_datasets.xls -- View this message in context: http://r.789695.n4.nabble.com/Interweaving-of-two-datasets-tp4608505p4622912.html Sent from the R help mailing list archive at Nabble.com.
With the sample data and the merge as above,
table(res2$phone)
454 2123 2342 9876 56775 87678
2 2 3 3 4 1
with(res2, table(name, request))
request
name book cigarettes drink food paper
Andy 0 1 0 0 0
Bruce 0 0 0 2 2
Ella 1 0 1 1 0
John 1 0 0 0 1
Luna 0 0 0 1 1
Morgana 1 1 0 1 0
Rui Barradas
lunarossa wrote>
> Hi Rui, sorry for my vagueness. The problem is not the order.
>
> I tried to merge the datasets as you wrote. The result is that when I
> input:
>
> table(phone)
>
> The output is:
> 0
>
> And this happens for all the variables.
>
--
View this message in context:
http://r.789695.n4.nabble.com/Interweaving-of-two-datasets-tp4608505p4623724.html
Sent from the R help mailing list archive at Nabble.com.
I don't quite follow what you are doing. Here is what Rui was suggesting
using your sample data
==================================================================dat1 <-
structure(list(name = structure(c(4L, 3L, 5L, 2L, 1L, 6L), .Label =
c("Andy",
"Bruce", "Ella", "John", "Luna",
"Morgana"), class = "factor"),
address = structure(c(2L, 4L, 1L, 3L, 2L, 4L), .Label = c("Kiev
street",
"london road", "main avenue", "Rome street"),
class = "factor"),
phone = c(2123L, 2342L, 454L, 56775L, 287678L, 39876L)), .Names =
c("name",
"address", "phone"), class = "data.frame",
row.names = c(NA,
-6L))
dat2 <- structure(list(name = structure(c(4L, 4L, 3L, 3L, 3L, 5L, 5L,
2L, 2L, 2L, 2L, 1L, 6L, 6L, 6L), .Label = c("Andy", "Bruce",
"Ella", "John", "Luna", "Morgana"),
class = "factor"), request = structure(c(1L,
5L, 4L, 1L, 3L, 4L, 5L, 5L, 5L, 4L, 4L, 2L, 1L, 4L, 2L), .Label =
c("book",
"cigarettes", "drink", "food", "paper"),
class = "factor")), .Names = c("name",
"request"), class = "data.frame", row.names = c(NA, -15L))
mydata <- merge(dat1, dat2)
mydata
==================================================================#If you need
information about a variable in the merge try something like:
table(mydata$phone)
Is this of any help?
John Kane
Kingston ON Canada
> -----Original Message-----
> From: gloriaalbe1 at yahoo.it
> Sent: Thu, 10 May 2012 07:33:45 -0700 (PDT)
> To: r-help at r-project.org
> Subject: Re: [R] Interweaving of two datasets
>
> Hi Ruri, sorry for my vagueness. The problem is not the order.
>
> I tried to merge the datasets as you wrote. The result is that when I
> input:
>
> table(phone)
>
> The output is:
> 0
>
> And this happens for all the variables.
>
> --
> View this message in context:
>
http://r.789695.n4.nabble.com/Interweaving-of-two-datasets-tp4608505p4623672.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.
____________________________________________________________
GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at
http://www.inbox.com/smileys
Works with AIM?, MSN? Messenger, Yahoo!? Messenger, ICQ?, Google Talk? and most
webmails