Re: [R] Iterations

From: Michael Rennie <mdrennie_at_gmail.com>
Date: Tue, 15 Jul 2008 13:39:11 -0400

for(1 in 1:10)

     {
     print(i)
     }

Mike

On Tue, Jul 15, 2008 at 1:11 PM, <rkevinburton_at_charter.net> wrote:
> I have a command that reads in some data:
>
> x <- read.csv("Sales2007.dat", header=TRUE)
>
> Then I try to organize the data:
>
> sc <- split(x, list(x$Category, x$SubCategory), drop=TRUE)
>
> Then I want to iterate through the data. I was able to get the following to run on the R console:
>
> for(i in 1:length(sc))
> {
> sum(sc[[i]]$Quantity)
> }
>
> But notiing is primted on the console. I find that:
>
> for(i in 1:100)
> {
> i
> }
>
> Also does't output anything? I am probably making a wrong assumption here. Why desn't the loop seem to output anyything?
>
> Thank you.
>
> Kevin
>
> ______________________________________________
> 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.
>

-- 
--
Michael D. Rennie
Ph.D. Candidate
University of Toronto at Mississauga
3359 Missisagua Rd. N.
Mississauga, ON L5L 1C6
Ph: 905-828-5452 Fax: 905-828-3792
www.utm.utoronto.ca/~w3rennie

______________________________________________
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.
Received on Tue 15 Jul 2008 - 18:01:17 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 15 Jul 2008 - 18:31:54 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive