Hi All,
I'm trying to split my dataset, into multiple datasets that i'll analyse
later, i wanted to do this dynamically as i might need to rerun the code
later.
I was looking at doing this via a loop, (Are other methods more appropriate?
Would a function be better?)
However i'm not sure in R how do do string replacement within the loop in
order to create unique dataset names based on the number of 'Groups' i
have
Many thanks
Mike
my code is as follows:
no.groups <-names(table(Conv$Group))
for (i in length(Conv$no.groups))
{
groupi <- subset(Conv, Conv$Group == i)
}
Metal Secs cost Income stable Group
1 Chrome 60 14 3.3458 1 2
2 Chrome 51 10 1.8561 0 1
3 Chrome 24 12 0.6304 0 1
4 Chrome 38 8 3.4183 1 2
5 Chrome 25 12 2.7852 1 3
6 Chrome 67 12 2.3866 1 1
7 Chrome 40 12 4.2857 0 1
8 Chrome 56 10 9.3205 1 1
9 Chrome 32 12 3.8797 1 3
10 Chrome 75 16 2.7031 1 3
11 Chrome 46 15 11.2307 1 2
12 Chrome 52 12 8.6696 1 2
13 Chrome 22 12 1.7443 0 2
14 Chrome 60 12 0.2253 0 2
15 Chrome 24 14 4.3348 1 3
--
Michael Pearmain
Senior Analytics Research Specialist
Google UK Ltd
Belgrave House
76 Buckingham Palace Road
London SW1W 9TQ
United Kingdom
t +44 (0) 2032191684
mpearmain@google.com
If you received this communication by mistake, please don't forward it to
anyone else (it may contain confidential or privileged information), please
erase all copies of it, including all attachments, and please let the sender
know it went to the wrong person. Thanks.
[[alternative HTML version deleted]]
Try this: split(Conv, Conv$Group) On Fri, Dec 5, 2008 at 11:28 AM, Michael Pearmain <mpearmain@google.com>wrote:> Hi All, > I'm trying to split my dataset, into multiple datasets that i'll analyse > later, i wanted to do this dynamically as i might need to rerun the code > later. > I was looking at doing this via a loop, (Are other methods more > appropriate? > Would a function be better?) > > However i'm not sure in R how do do string replacement within the loop in > order to create unique dataset names based on the number of 'Groups' i have > > Many thanks > > Mike > > my code is as follows: > > no.groups <-names(table(Conv$Group)) > for (i in length(Conv$no.groups)) > { > groupi <- subset(Conv, Conv$Group == i) > } > > > Metal Secs cost Income stable Group > 1 Chrome 60 14 3.3458 1 2 > 2 Chrome 51 10 1.8561 0 1 > 3 Chrome 24 12 0.6304 0 1 > 4 Chrome 38 8 3.4183 1 2 > 5 Chrome 25 12 2.7852 1 3 > 6 Chrome 67 12 2.3866 1 1 > 7 Chrome 40 12 4.2857 0 1 > 8 Chrome 56 10 9.3205 1 1 > 9 Chrome 32 12 3.8797 1 3 > 10 Chrome 75 16 2.7031 1 3 > 11 Chrome 46 15 11.2307 1 2 > 12 Chrome 52 12 8.6696 1 2 > 13 Chrome 22 12 1.7443 0 2 > 14 Chrome 60 12 0.2253 0 2 > 15 Chrome 24 14 4.3348 1 3 > > > > > -- > Michael Pearmain > Senior Analytics Research Specialist > > > Google UK Ltd > Belgrave House > 76 Buckingham Palace Road > London SW1W 9TQ > United Kingdom > t +44 (0) 2032191684 > mpearmain@google.com > > If you received this communication by mistake, please don't forward it to > anyone else (it may contain confidential or privileged information), please > erase all copies of it, including all attachments, and please let the > sender > know it went to the wrong person. Thanks. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]