Re: [R] R code output issues

2010-09-03 Thread Marcel Curlin

Thanks for the input

Adding "print" took care of the first problem. The output looks like what I
would expect, so I think the code is doing what I would like it to for the
first 44 observations. 

> print(results.df)
  DR  D.1  R.1 V1V2dif V1V4dif
1  68.92500 75.0 284.5250 296.   6.075  11.475
2  68.81081 67.0 287.7568 283.  -1.8108108  -4.7567568
3  65.43902 62.0 282.5366 279.  -3.4390244  -3.5365854
4  66.6 67.25000 286.7000 288.2500   0.650   1.550
5  68.94872 71.0 297.8462 305.   2.0512821   7.1538462
Etc..

When I use str(results.df) it does seem to indicate a short file of 44
observations.  

'data.frame':44 obs. of  6 variables:
 $ D  : num  68.9 68.8 65.4 66.6 68.9 ...
 $ R  : num  75 67 62 67.2 71 ...
 $ D.1: num  285 288 283 287 298 ...
 $ R.1: num  296 283 279 288 305 ...
 $ V1V2dif: num  6.08 -1.81 -3.44 0.65 2.05 ...
 $ V1V4dif: num  11.48 -4.76 -3.54 1.55 7.15 ...

So I am still left with that question..
-- 
View this message in context: 
http://r.789695.n4.nabble.com/R-code-output-issues-tp2526415p2526469.html
Sent from the R help mailing list archive at Nabble.com.

__
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.


Re: [R] R code output issues

2010-09-03 Thread jim holtman
first of all if you are 'sourcing' the file, put explicit print calls
on your data frame; e.g., print(dataframe).  Just because your input
is 2149 lines long does not mean you results will necessarily be that
long.  You are using 'tapply' which will be aggregating your data.
You need to provide some reproducible data and code so we can see what
is happening.  My best guess is you are getting the results from the
tapply that you were not expecting.  Some simple debugging on your
part looking at the partial results would point you in the right
direction.  What does 'str' of you data fram say; I bet it says you
have 46 observations.

On Fri, Sep 3, 2010 at 8:32 PM, Marcel Curlin  wrote:
>
> Hi all,
> I have a short R code file that I am using to perform calculations on a
> dataset. I am having a few issues with output:
>
> 1. Although my input data file is 2149 lines long, when I type "results.df"
> from the command line, I get the appropriate calculation results for only
> the first 46 rows. Same result if I "sink" the output to a file, and type
> "results.df" at the command line. This creates a file with the first 46
> entries. I do get the entire input data file back if I type "data", and I
> can't see anything in my input file around line 46 that would account for
> this.
>
> 2. If I run the code from a file using the command
> "source("TransmissionCalc2") with the "results.df" command embedded in the
> file, there is no output to the terminal at all (or to the output file, if I
> use sink). Sink just creates an empty file.
>
> So, not sure why my results dataframe seems to only include a small fraction
> of the data, or why the write commands are ignored when embedded in the code
> and called by "source("etc"
>
> CODE
>
> rm(list = ls(all = TRUE))
> alldata
> <-read.table("/Users/marcel/Desktop/V1V2TransmAnalysis/3_transmissiondata",
> header=T)
> #sink("/Users/marcel/Desktop/V1V2TransmAnalysis/4_output")
> data <- data.frame(alldata)
> V1V2means <- with(data, tapply(V1V2, list(Pair, DR), mean))
> V1V4means <- with(data, tapply(V1V4, list(Pair, DR), mean))
> results.df <- data.frame(V1V2means, V1V4means, V1V2dif = V1V2means[, "R"] -
> V1V2means[, "D"], V1V4dif = V1V4means[, "R"] - V1V4means[, "D"] )
> data
>
> SAMPLE OF INPUT DATA FILE
>
> Pair    DR    V1V2    V1V4
> 1    D    63    277
> 1    D    63    277
> 1    D    63    277
> .
>
>
> Thoughts greatly appreciated.
>
> Marcel
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/R-code-output-issues-tp2526415p2526415.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

__
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.


[R] R code output issues

2010-09-03 Thread Marcel Curlin

Hi all,
I have a short R code file that I am using to perform calculations on a
dataset. I am having a few issues with output: 

1. Although my input data file is 2149 lines long, when I type "results.df"
from the command line, I get the appropriate calculation results for only
the first 46 rows. Same result if I "sink" the output to a file, and type
"results.df" at the command line. This creates a file with the first 46
entries. I do get the entire input data file back if I type "data", and I
can't see anything in my input file around line 46 that would account for
this. 

2. If I run the code from a file using the command
"source("TransmissionCalc2") with the "results.df" command embedded in the
file, there is no output to the terminal at all (or to the output file, if I
use sink). Sink just creates an empty file. 

So, not sure why my results dataframe seems to only include a small fraction
of the data, or why the write commands are ignored when embedded in the code
and called by "source("etc" 

CODE

rm(list = ls(all = TRUE))
alldata
<-read.table("/Users/marcel/Desktop/V1V2TransmAnalysis/3_transmissiondata",
header=T)
#sink("/Users/marcel/Desktop/V1V2TransmAnalysis/4_output")
data <- data.frame(alldata)
V1V2means <- with(data, tapply(V1V2, list(Pair, DR), mean))
V1V4means <- with(data, tapply(V1V4, list(Pair, DR), mean))
results.df <- data.frame(V1V2means, V1V4means, V1V2dif = V1V2means[, "R"] -
V1V2means[, "D"], V1V4dif = V1V4means[, "R"] - V1V4means[, "D"] )
data

SAMPLE OF INPUT DATA FILE

PairDRV1V2V1V4
1D63277
1D63277
1D63277
.


Thoughts greatly appreciated.

Marcel
-- 
View this message in context: 
http://r.789695.n4.nabble.com/R-code-output-issues-tp2526415p2526415.html
Sent from the R help mailing list archive at Nabble.com.

__
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.