Re: [R] How to direct R to read commands from a text file

2015-10-30 Thread Boris Steipe
I should think this thread contains all you need: http://stackoverflow.com/questions/18306362/run-r-script-from-command-line B. On Oct 30, 2015, at 11:07 PM, Gregory Coats wrote: > All of the R commands that I want to issue are in a text file that concludes > with the R command quit (save

[R] How to direct R to read commands from a text file

2015-10-30 Thread Gregory Coats
All of the R commands that I want to issue are in a text file that concludes with the R command quit (save = “yes”), and is called R_commands.txt. I can start R, and then manually issue source (“R_commands.txt”). But I would prefer to issue, from the bash command line, a one line command, direct

[R] How to add legend to 2 different data frame overplot?

2015-10-30 Thread C W
Hi, I am trying to do add a legend to an overplot, something like this: ggplot() + geom_density(data = df1, aes(x = x), fill = "green", show_guide = FALSE) + geom_area(data = df2, aes(x = x), fill = "yellow", show_guide = FALSE) + scale_color_manual(values = c("green", "yellow"), labe

[R] A simple crop/clip of a png map

2015-10-30 Thread Jim Burke
I have a 5.76" x 5.75" png image which I would like to crop to some inch size. To use as a report header (after placing some title text on it). So how to use R to crop a nice rectangle from my image? Thanks for your thoughts Jim Burke [[alternative HTML version deleted]] ___

[R] Nested ANOVA yields surprising results

2015-10-30 Thread Daniel Wagenaar
Dear R users: All textbook references that I consult say that in a nested ANOVA (e.g., A/B), the F statistic for factor A should be calculated as F_A = MS_A / MS_(B within A). But when I run this simple example: set.seed(1) A <- factor(rep(1:3, each=4)) B <- factor(rep(1:2, 3, each=2)) Y <-

Re: [R] [FORGED] If else

2015-10-30 Thread Rolf Turner
On 31/10/15 14:15, Val wrote: Hi all, Iam trying to change character to numeric but have probelm mydata <- read.table(header=TRUE, text=', sep=" " id sex 1 NA 2 NA 3 M 4 F 5 M 6 F 7 F ') if sex is missing then sex=0; if sex

Re: [R] If else

2015-10-30 Thread Val
I am trying to change the mydata$sex from character to numeric I want teh out put like id sex 1 NA 0 2 NA 0 3 M 1 4 F 2 5 M1 6 F 2 7 F2 mydata$sex1 <- 0 if(mydata$sex =="M " ){ mydata$sex1<-1 } else { mydata$sex1<-2

Re: [R] If else

2015-10-30 Thread Ista Zahn
Using numeric for missing sounds like asking for trouble. But if you must, something like mydata$confusingWillCauseProblemsLater <- ifelse( is.na(mydata$sex), 0, as.numeric(factor(mydata$sex, levels = c("M", "F" should do it. Best, Ista On Fri, Oct 30, 20

[R] If else

2015-10-30 Thread Val
Hi all, Iam trying to change character to numeric but have probelm mydata <- read.table(header=TRUE, text=', sep=" " id sex 1 NA 2 NA 3 M 4 F 5 M 6 F 7 F ') if sex is missing then sex=0; if sex is"M" then sex=1; if sex is"F" then sex=

Re: [R] Nested effects (was: "no subject")

2015-10-30 Thread Rolf Turner
On 31/10/15 03:32, Wagenaar, Daniel (wagenadl) wrote: Dear R users: All textbook references that I consult say that in a nested ANOVA (e.g., A/B), the F statistic for factor A should be calculated as F_A = MS_A / MS_(B within A). But when I run this simple example: set.seed(1) A = factor(rep(1:

Re: [R] ggplot2: Controlling width of line

2015-10-30 Thread Jeff Newmiller
Not sure why you are making this so complicated. In what way is the following not meeting your expectations? ggplot( data=matz , aes( x = X1 , y = value , col=X2 , lty=X2 , shape=X2 , size=mylwd ) ) + geom_line() +

Re: [R] how to work with time of day (independent of date)

2015-10-30 Thread Jeff Newmiller
Sys.setenv( TZ="Etc/GMT+8" ) executed before converting to POSIXct works for me, though using that string with the tz parameter also works. You should read ?Sys.timezone. For windows, look at the files in C:\Program Files\R\R-3.2.2\share\zoneinfo and note that PST is not defined though PST8PDT

Re: [R] how to work with time of day (independent of date)

2015-10-30 Thread William Dunlap
I get confused by this also, but I believe your time zone is US/Pacific, which specifies both the offset from UTC and the dates on which we switch between 'standard' (winter) and 'daylight savings' (summer). I think you would have to create a new time zone entry that is always UTC+8 hours, or what

Re: [R] how to work with time of day (independent of date)

2015-10-30 Thread Clint Bowman
Bill, Your final words, "changes in spring and fall" reminds me of a problem I have yet to solve. Most of my data is logged in standard time (no daylight times) but often I see the note "daylight time encountered switching to UTC" even when I've specified "tz="PST". I hope I've been missing

Re: [R] how to work with time of day (independent of date)

2015-10-30 Thread Daniel Nordlund
On 10/30/2015 11:17 AM, Mark Leeds wrote: Daniel: Just to complete my solution, here's the code for doing the mean. Didn't expect this to take 3 emails !!! Have a good weekend. temp <- tapply(f$value, f$justtimes, mean) finalDF <- data.frame(chrontimes = times(rownames(temp)), values = temp) plo

Re: [R] (no subject)

2015-10-30 Thread Kevin Wright
Maybe you want summary(aov(Y ~ A + Error(A:B))) Kevin On Fri, Oct 30, 2015 at 9:32 AM, Wagenaar, Daniel (wagenadl) < wagen...@ucmail.uc.edu> wrote: > Dear R users: > > All textbook references that I consult say that in a nested ANOVA (e.g., > A/B), the F statistic for factor A should be calcul

Re: [R] how to work with time of day (independent of date)

2015-10-30 Thread William Dunlap
You can use difftime objects to get the amount of time since the start of the current day. E.g., > dateTime <- as.POSIXlt( c("2015-10-29 00:50:00", + "2015-10-29 09:30:00", "2015-10-29 21:10:00", "2015-10-30 00:50:00", + "2015-10-30 09:30:00", "2015-10-30 21:10:00", "2015-10-31 00:50:00",

Re: [R] how to work with time of day (independent of date)

2015-10-30 Thread jim holtman
is this what you want: > df <- structure(list(date = structure(1:8, .Label = c("2015-10-29 00:50:00", + "2015-10-29 09:30:00", "2015-10-29 21:10:00", "2015-10-30 00:50:00", + "2015-10-30 09:30:00", "2015-10-30 21:10:00", "2015-10-31 00:50:00", + "2015-10-31 10:30:00"), class = "factor"), value = c

[R] how to work with time of day (independent of date)

2015-10-30 Thread Daniel Nordlund
I have a data frame with date/times represented as charaacter strings and and a value at that date/time. I want to get the mean value for each time of day, across days, and then plot time of day on the x-axis and means on the y-axis. R doesn't appear to have a built-in time of day time type (

Re: [R] Error: Invalid First Argument in DPlyr

2015-10-30 Thread Jeff Newmiller
You need to divide and conquer... find out which step is breaking the pipe by terminating it early at various points and if the problem is still not clear one you know which step is broken then give us a reproducible example. I am not familiar with RSQLServer specifically, but the version of dpl

[R] Error: Invalid First Argument in DPlyr

2015-10-30 Thread Abraham Mathew
I'm getting an "invalid first argument" error for the following. However, con is an actual connection and is set up properly. So what does this error actually refer to? library(dplyr) con <- RSQLServer::src_sqlserver("***", database = "***") myData <- con %>% tbl("table") %>% group_by( work_d

[R] (no subject)

2015-10-30 Thread Wagenaar, Daniel (wagenadl)
Dear R users: All textbook references that I consult say that in a nested ANOVA (e.g., A/B), the F statistic for factor A should be calculated as F_A = MS_A / MS_(B within A). But when I run this simple example: set.seed(1) A = factor(rep(1:3, each=4)) B = factor(rep(1:2, 3, each=2)) Y = rnorm(

Re: [R] User-defined functions in dplyr

2015-10-30 Thread William Dunlap
dplyr::mutate is probably what you want instead of dplyr::summarize: create_bins3 <- function (xpred, nBins) { Breaks <- unique(quantile(xpred, probs = seq(0, 1, 1/nBins))) bin <- cut(xpred, breaks = Breaks, include.lowest = TRUE) bin } dplyr::group_by(df, models) %>% dplyr::mutate(Bin

Re: [R] User-defined functions in dplyr

2015-10-30 Thread William Dunlap
The error message is not very helpful and the stack trace is pretty inscrutable as well > dplyr::group_by(df, models) %>% dplyr::summarize(create_bins) Error: not a vector > traceback() 14: stop(list(message = "not a vector", call = NULL, cppstack = NULL)) 13: .Call("dplyr_summarise_impl", PACKAGE

[R] ggplot2: Controlling width of line

2015-10-30 Thread Brian Smith
Hi, I was trying to increase the size of certain lines in my plot (samples 'B' and 'D' in example below). However, when I try to modify the line size, I seem to screw up the linetypes. Also, is there a way to reflect the line size in the legend? Here is some sample code for illustration: library

Re: [R] Achieve independent fine user control of ggplot geom settings when using groups in multiple geom's

2015-10-30 Thread sbihorel
Thanks Hadley, I will certainly read your book. Unfortunately, what you just confirmed as the developer of ggplot means that ggplot is non-starter for what I want to build. Too bad, I was starting to appreciate some of its advantages over lattice. About your book, in case I do not find a pro

Re: [R] monte carlo simulations in permanova in vegan package

2015-10-30 Thread Sean Porter
Thank you Jari, It seems now that my question is morphing more into a statistical one, and perhaps not appropriate for R-help list, so apologies. Yes we are talking about the latest versions of the vegan and permute packages. When there are an insufficient number of permutations available due to

Re: [R] Achieve independent fine user control of ggplot geom settings when using groups in multiple geom's

2015-10-30 Thread Hadley Wickham
I'd recommend reading the ggplot2 book - learning more about how scales work in ggplot2 will help you understand why this isn't possible. Hadley On Thu, Oct 29, 2015 at 6:31 PM, sbihorel wrote: > Thank for your reply, > > I may accept your point about the mapping consistency when the different >

Re: [R] User-defined functions in dplyr

2015-10-30 Thread Axel Urbiz
So in this case, "create_bins" returns a vector and I still get the same error. create_bins <- function(x, nBins) { Breaks <- unique(quantile(x$pred, probs = seq(0, 1, 1/nBins))) bin <- cut(x$pred, breaks = Breaks, include.lowest = TRUE) bin } ### Using dplyr (fails) nBins = 10 by_group <

Re: [R] monte carlo simulations in permanova in vegan package

2015-10-30 Thread Sean Porter
Thank you Jari, It seems now that my question is morphing more into a statistical one, and perhaps not appropriate for R-help list, so apologies. Yes we are talking about the latest versions of the vegan and permute packages. When there are an insufficient number of permutations available due to