[R] Plotting accumulated data

2011-01-28 Thread Ottar Kvindesland
Hello all

I have the data frame with this:

 ID  DATETIME TRN  TRN_S
1 1192756 2010-06-23 15:39:07 13.420 0.2236667
2 1192757 2010-06-23 15:40:07 13.805 0.2300833
3 1192758 2010-06-23 15:41:07 13.860 0.231
4 1192759 2010-06-23 15:42:07 13.750 0.2291667
5 1192760 2010-06-23 15:43:07 13.530 0.2255000
6 1192761 2010-06-23 15:44:07 13.805 0.2300833

Now, I would like to plot a graph with DATETIME and the accumulated
TRN_S.

I can run a while loop like this:

accumulated_trns <- 0
last_value <-length(data$TRN_S)
while (i < last_value) {
acc_trns <- acc_trns + data$TRN_S[i]
data$accumulated_trns[i] <- acc_trns
i <- i + 1
}
data$accumulated_trns[i] <- acc_trns
plot(data$DATETIME, data$accumulated_trns)


This is slow and demanding on the computer.

There must be a better way to accumulate values! Any suggestion greatly
appreciated.

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


Re: [R] Removing NA in ggplot

2010-11-06 Thread Ottar Kvindesland
OK, any reason why ggplot2 does not allow filtering of NA?


ottar

On 6 November 2010 15:23, Jeff Newmiller  wrote:

> Create a subset of your data that excludes the NAs before you feed it to
> ggplot.
>
> "Ottar Kvindesland"  wrote:
>
> >Hi list,
> >
> >I just got stuck with this one:
> >
> >In Data I have the sets age (numbers 1 to 99 and NA) and gender (M, F
> >and
> >NA). Then getting some nice plots using
> >
> >ggplot(data, aes(age[na.exclude(gender)])) +
> >geom_histogram( binwidth = 3, aes(y = ..density.. ), fill = "lightblue"
> >)
> >+
> >  facet_grid( gender ~ .)
> >
> >I am trying to get a faceted graph of age distribution excluding the NA
> >data
> >for gender
> >
> >Unfortunately I end up with the error message:
> >
> >Error in data.frame(..., check.names = FALSE) :
> >arguments imply differing number of rows: 206, 219
> >
> >How do i Wash out NA's in this situation?
> >
> >
> >Regards
> >
> >ottar
> >
> >   [[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.
>
> ---
> Jeff NewmillerThe .   .  Go Live...
> DCN:Basics: ##.#.   ##.#.  Live
> Go...
>  Live:   OO#.. Dead: OO#..  Playing
> Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
> /Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
> ---
> Sent from my phone. Please excuse my brevity.
>

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


[R] Removing NA in ggplot

2010-11-06 Thread Ottar Kvindesland
Hi list,

I just got stuck with this one:

In Data I have the sets age (numbers 1 to 99 and NA) and gender (M, F and
NA). Then getting some nice plots using

ggplot(data, aes(age[na.exclude(gender)])) +
 geom_histogram( binwidth = 3, aes(y = ..density.. ), fill = "lightblue" )
+
  facet_grid( gender ~ .)

I am trying to get a faceted graph of age distribution excluding the NA data
for gender

Unfortunately I end up with the error message:

Error in data.frame(..., check.names = FALSE) :
arguments imply differing number of rows: 206, 219

How do i Wash out NA's in this situation?


Regards

ottar

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


Re: [R] Time in ggplot2

2010-06-22 Thread Ottar Kvindesland
Excellent, thanks. This solved it.



ottar



On 22 June 2010 11:39, Hadley Wickham  wrote:

> Hi Ottar,
>
> It's a bug in the code that automatically figures out the axis ticks.
> I have some code to fix it, but it's waiting for a release of another
> package.  In the meantime, you can work around it by specifying where
> you want the breaks:
>
> ggplot(data, aes(time, PU) ) +
>  geom_line() +
>  scale_x_datetime(major = "3 hours")
>
> Hadley
>
> PS.  You can make the code completely reproducible with (e.g.)
> load(url("http://master.kvindesland.no/R/failed_data.Rdata";))
>
> On Mon, Jun 21, 2010 at 3:24 PM, Ottar Kvindesland
>  wrote:
> > Thanks Hadley for taking the interest here.
> >
> > The data sets are a bit large and I have placed them available for your
> > download on
> > http://master.kvindesland.no/R/
> > You will find datasets in both Rdata and dput format. It seems that some
> > data sets works nicely and others do not even if they come from a very
> > similar SQL set. The select clause carries more coloumns in the failing
> data
> > set.
> >
> > ottar
> >
> > On 20 June 2010 18:28, Hadley Wickham  wrote:
> >>
> >> Hi Ottar,
> >>
> >> It's impossible to tell what the problem is without a reproducible
> >> example (http://gist.github.com/270442)
> >>
> >> Hadley
> >>
> >> On Sun, Jun 20, 2010 at 4:38 PM, Ottar Kvindesland
> >>  wrote:
> >> > I have a problem that puzzles me a bit today. When loading off data
> from
> >> > a
> >> > database and plotting using ggplot2, I wish to present data as a time
> >> > series
> >> > with time of day. The code is text-book like as shown below:
> >> >
> >> > # Fetch data
> >> > con <- dbConnect(dbDriver("MySQL"), user="user", password = "pwd",
> >> > dbname="db")
> >> > data <- dbGetQuery(con, "select PU, DateTime from rep;")
> >> > data$time <- as.POSIXct(data$DateTime)
> >> > attach(data)
> >> >
> >> > # Plot Data
> >> > p <- ggplot(data, aes(x=time, colour=PU ) ) +
> >> > ylim( c(0, max(PU)) ) +
> >> > geom_line( aes(x=time, PU ) )
> >> >
> >> > p
> >> >
> >> > It starts plotting and terminates before anything is drawn on the
> >> > canvas.
> >> > The error message on the terminal is:
> >> >
> >> > Error in seq.int(0, to - from, by) : 'to' must be finite
> >> >
> >> > The DateTime coloumn in MySQL is of type datetime Is it a bug or a
> >> > feature?
> >> >
> >> >
> >> >
> >> > Thanks
> >> >
> >> > ottar
> >> >
> >> >[[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.
> >> >
> >>
> >>
> >>
> >> --
> >> Assistant Professor / Dobelman Family Junior Chair
> >> Department of Statistics / Rice University
> >> http://had.co.nz/
> >
> >
>
>
>
> --
> Assistant Professor / Dobelman Family Junior Chair
> Department of Statistics / Rice University
> http://had.co.nz/
>

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


Re: [R] Time in ggplot2

2010-06-21 Thread Ottar Kvindesland
Thanks Hadley for taking the interest here.

The data sets are a bit large and I have placed them available for your
download on

http://master.kvindesland.no/R/

You will find datasets in both Rdata and dput format. It seems that some
data sets works nicely and others do not even if they come from a very
similar SQL set. The select clause carries more coloumns in the failing data
set.


ottar


On 20 June 2010 18:28, Hadley Wickham  wrote:

> Hi Ottar,
>
> It's impossible to tell what the problem is without a reproducible
> example (http://gist.github.com/270442)
>
> Hadley
>
> On Sun, Jun 20, 2010 at 4:38 PM, Ottar Kvindesland
>  wrote:
> > I have a problem that puzzles me a bit today. When loading off data from
> a
> > database and plotting using ggplot2, I wish to present data as a time
> series
> > with time of day. The code is text-book like as shown below:
> >
> > # Fetch data
> > con <- dbConnect(dbDriver("MySQL"), user="user", password = "pwd",
> > dbname="db")
> > data <- dbGetQuery(con, "select PU, DateTime from rep;")
> > data$time <- as.POSIXct(data$DateTime)
> > attach(data)
> >
> > # Plot Data
> > p <- ggplot(data, aes(x=time, colour=PU ) ) +
> > ylim( c(0, max(PU)) ) +
> > geom_line( aes(x=time, PU ) )
> >
> > p
> >
> > It starts plotting and terminates before anything is drawn on the canvas.
> > The error message on the terminal is:
> >
> > Error in seq.int(0, to - from, by) : 'to' must be finite
> >
> > The DateTime coloumn in MySQL is of type datetime Is it a bug or a
> feature?
> >
> >
> >
> > Thanks
> >
> > ottar
> >
> >[[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.
> >
>
>
>
> --
> Assistant Professor / Dobelman Family Junior Chair
> Department of Statistics / Rice University
> http://had.co.nz/
>

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


[R] Time in ggplot2

2010-06-20 Thread Ottar Kvindesland
I have a problem that puzzles me a bit today. When loading off data from a
database and plotting using ggplot2, I wish to present data as a time series
with time of day. The code is text-book like as shown below:

# Fetch data
con <- dbConnect(dbDriver("MySQL"), user="user", password = "pwd",
dbname="db")
data <- dbGetQuery(con, "select PU, DateTime from rep;")
data$time <- as.POSIXct(data$DateTime)
attach(data)

# Plot Data
p <- ggplot(data, aes(x=time, colour=PU ) ) +
ylim( c(0, max(PU)) ) +
geom_line( aes(x=time, PU ) )

p

It starts plotting and terminates before anything is drawn on the canvas.
The error message on the terminal is:

Error in seq.int(0, to - from, by) : 'to' must be finite

The DateTime coloumn in MySQL is of type datetime Is it a bug or a feature?



Thanks

ottar

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


[R] Zero counts lost with table() in functions

2010-06-14 Thread Ottar Kvindesland
Hi,

I am collecting replies from a survey and counts replies by the table()
function. The function below carries two
data frames and counts the observations of the findings in the first
parameter vector given the value of the second as shown in the code below.

My trouble is that the vector kp_vec at the end of the inner loop seems to
ignore the value when the
table() counts zero occurences of one of the outcomes. I will have

y n
34   0

This is not picked up in the matrix row after the loops with something like

 "y"   "n" "y"
"Funding"   "Survival"  12 5   34

where the last "n" value is missing. This causes my returned data frame to
fail and in all, rather miserable for the plot.

I see the point of this in a way, so I believe it is not a bug. I'd love to
get my zero back. Is it a subtle point in R I have missed?


kpi_test <- function ( paramvec, kpivec ) {
kp_vec <- c()
res_kpi_y <- c()
res_kpi_n <- c()

tmp_param <- c()
tmp_kpi <- c()

for(param_no in seq(from=1, to=length(paramvec), by = 1)) {
tmp_param <- paramvec[param_no]
for (kpi_no in seq(from=1, to=length(kpivec), by = 1)) {
tmp_kpi <- kpivec[kpi_no]
res_kpi_y <- table( tmp_param [ tmp_kpi == 'y' ] )
res_kpi_n <- table( tmp_param [ tmp_kpi == 'n' ] )
kp_vec <- c(kp_vec, names(tmp_param), names(tmp_kpi), res_kpi_y, res_kpi_n )
}
}
matrix_vector <- matrix(kp_vec, ncol=6, byrow=T)
fres <- data.frame(matrix_vector)
return( fres )
}


ottar

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


[R] Analyzing non-numerical data

2010-05-03 Thread Ottar Kvindesland
After having read through some literature on R, I am happy with collecting
it, and visualizing numbers. Unfortunately I do find it hard to compare and
visualize string data. The data is from a LimeSurvey with lots of YES/NO or
multi-choice questions (check-boxes)

Among the check-boxes there a couple of options with the data are (Ikke
valgt=NOT CHECKED, Ja= CHECKED):

> data$perf_none
[1] Ikke valgt Ikke valgt Ikke valgt Ikke valgt Ikke valgt Ikke valgt
[7] Ikke valgt Ikke valgt Ikke valgt Ikke valgt Ikke valgt Ja
[13] Ja Ikke valgt Ikke valgt Ikke valgt Ikke valgt Ikke valgt

> data$perf_pct
[1] Ikke valgt Ikke valgt Ikke valgt Ja Ja Ja
[7] Ikke valgt Ikke valgt Ja Ja Ja Ikke valgt
[13] Ikke valgt Ikke valgt Ja Ikke valgt Ikke valgt Ja

A yes/no question as below.

> data$suppl
[1]  Ja Ja  Nei Ja  Ja   Nei  Nei Ja Nei
[16] Ja Ja Ja Ja  Ja Nei Nei Nei Ja Nei Ja   Ja

I can run command like plot(data$perf_none) and that is about it.

It gets a bit tricky when the literature refers to examples where all data
is numeric and not text like here.

Could anyone point me in a direction for more helpful investigations like
searching correlations.
I would also like to be able to visualize the data from such non-numeric
vectors.

The question is general but examples and hints would be appreciated.



ok

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


[R] Using R to analyze limesurvey data

2010-03-24 Thread Ottar Kvindesland
Hello everyone,

I have a survey on LimeSurvey ( https://www.limeservice.com/ ) going and I
am preparing data analysis. Data exports to R dumps are completed and works.

I have slowly started learning R but would really appreciate some assistance
in helping me fly faster. I do understand that this attitude may not be
entirely compliant with the philosophy of R. Still, please appreciate the
survey is on management and the author has never been rewarded for his
patience.

If anyone have any R scripts from a Lime Survey or analysis of such a thing,
I would be very grateful if you would share it on this list or publish a
link to such scripts.


Best regards

ottar

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