[R] R code output issues

jim holtman jholtman at gmail.com
Sat Sep 4 03:52:18 CEST 2010


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 <cemarcel at u.washington.edu> 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 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.
>



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

What is the problem that you are trying to solve?



More information about the R-help mailing list