[R] Data manipulation - multiplicate cases

Bill.Venables at csiro.au Bill.Venables at csiro.au
Sat Mar 28 03:36:52 CET 2009


Here is a suggestion.  Let your data frame be 'dat':

> dat
X      Y    Z
123   3    1
234   3    1
345   4    2
456   3    2

Try this:

bigData <- data.frame(with(dat,
                rbind(cbind(X = rep(X,   Z), Y = rep(Y,    Y), Z = 1),
                        cbind(X = rep(X, Y-Z), Y = rep(Y, Y-Z), Z = 0))))

bigData <- with(bigData, bigData[order(X, -Y), ])


Bill Venables.
________________________________________
From: r-help-bounces at r-project.org [r-help-bounces at r-project.org] On Behalf Of MarcioRibeiro [mestat at pop.com.br]
Sent: 27 March 2009 06:26
To: r-help at r-project.org
Subject: [R]  Data manipulation - multiplicate cases

Hi listers,
I am trying to arrange my data and I didn't find any information how to do
it!
I have a data with 3 variables: X Y Z
1-I would like to multiplicate de information of X according to the number I
have for my Y variable...
2-Then I want to identify with a dicotomic variable by the number according
my variable Z from X...
I can do the first part by...
z<-rep(x,y)
But I don't know how to set a dicotomic variable according to Z...
Exemple...
I have...
X      Y    Z
123   3    1
234   3    1
345   4    2
456   3    2
I want to get...
X      Y    Z
123   3    1
123   3    0
123   3    0
234   3    1
234   3    0
234   3    0
345   4    1
345   4    1
345   4    0
345   4    0
456   3    1
456   3    1
456   3    0

Thanks in advance...
--
View this message in context: http://www.nabble.com/Data-manipulation---multiplicate-cases-tp22730453p22730453.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