in reply to Mean and standard deviation loop

Just dumping all your data here may be an efficient way for you to get your problems solved by someone else, but it isn't for the community.

At the very least you should make an attempt yourself.

I am willing to discuss code, not someone else's data-dump.

Replies are listed 'Best First'.
Re^2: Mean and standard deviation loop
by SixShot (Novice) on Jun 17, 2012 at 11:58 UTC
    ,p>ahh apologies, l totally understand what you mean. Here is the start of my scripy

    #!/usr/bin/perl -w # ------------------------------------------------- use strict; use Getopt::Long; use Pod::Usage; use File::Spec; Getopt::Long::Configure ("bundling"); # ------------------------------------------------- my $help = 0; my $force = 0; my $verbose = 0; my $result = GetOptions( "help|h" =>\$help, "force|f"=>\$force, "verbose|v"=>\$verbose, #-------------------------------------------------- # Assign input data to an arrray #--------------------------------------------------- scalar (@ARGV) == 1 or die pod2usage(1); my $fname = $ARGV[0]; my $fnameout = $fname; $fnameout =~ s/\.\w\w\w$/_conv.csv/; # ------------------------------------------------- (-e $fname) or die "Unable to find input file: $fname\n"; (-e $fnameout and $force) and die "Output file already exisys. Use -f +to force: $fnameout\n"; my ($fin, $fout); open ($fin, "<$fname") or die "Unable to open file: $fname\n"; open ($fout, ">$fnameout") or die "Unable to open output file: $fnameo +ut\n"; my @headers = qw (Col_1 Col_3 Mean St_Dev); print $fout (join (",", @headers),"\n"); # ------------------------------------------------- # Chomp all data # ------------------------------------------------- my @data = <$fin>; # ------------------------------------------------- my $cnt = 0; foreach my $line (@data) { $cnt ++; next unless $cnt > 1; # Skip Header chomp($line); }

    its just the input section, l really am stuck on how to loop over this my programmers mind is still quite novice im afraid and l am still struggling on working through loops in my mind.

      That is not an attempt to solve the problem at hand.

      It is just boiler-plate code (that you may simply have copied).

      Are you claiming you know how to read a file into an array but not how to loop in Perl?

      Your problem is to parse the data then partition the data and compute mean and std dev on the paritions.

      Before I provide any more feedback I would like to see an attempt there as otherwise I have the feeling you are simply trying to free-ride.

      This site is the Perl-monks, not the homework-monks.

        so this is were l am stuck, once l have the data into the @data array i am not sure how to work through this to to the stats calculation by matching the col1 and col2 ranges.

        #!/usr/bin/perl -w # ------------------------------------------------- use strict; use Getopt::Long; use Pod::Usage; use File::Spec; Getopt::Long::Configure ("bundling"); use Statistics::R; # ------------------------------------------------- my $help = 0; my $force = 0; my $verbose = 0; my $result = GetOptions( "help|h" =>\$help, "force|f"=>\$force, "verbose|v"=>\$verbose, ); #-------------------------------------------------- # Assign input data to an arrray #--------------------------------------------------- scalar (@ARGV) == 1 or die pod2usage(1); my $fname = $ARGV[0]; my $fnameout = $fname; $fnameout =~ s/\.\w\w\w$/_conv.csv/; # ------------------------------------------------- (-e $fname) or die "Unable to find input file: $fname\n"; (-e $fnameout and $force) and die "Output file already exisys. Use -f +to force: $fnameout\n"; my ($fin, $fout); open ($fin, "<$fname") or die "Unable to open file: $fname\n"; open ($fout, ">$fnameout") or die "Unable to open output file: $fnameo +ut\n"; my @headers = qw (Col_1 Col_3 Mean St_Dev); print $fout (join (",", @headers),"\n"); # ------------------------------------------------- # Chomp all data # ------------------------------------------------- my $cnt = 0; my @data=(); my $line; while (defined($line=<$fin>)) { $cnt ++; next unless $cnt > 1; # Skip Header chomp($line); next if $line =~ /^\s*$/; my @cols = split(',',$line); push @data,[@cols]; }

        I am just trying to put something together for you to look at right now, l know what is must look like but this is something l have written but im just struggling with the workings on this one. Give me a moment to knock something together based on my previous attenpts.