[R] Dates to numeric in for loop

2017-11-14 Thread Mikkel Grum
ot; [1] "Date" Why is this apparently not a bug? Are there other types that change type when looped over? Kind regards Mikkel _ *Mikkel Grum* +44 7377337321 (mobile) mikkelgrum (Skype) [[alternative HTML version deleted]] ___

Re: [R] ftables package, zero rows

2008-09-03 Thread Mikkel Grum
Does this help? a <- c(1,1,1,1,1,2,2,2,2,2) b <- c(4,5,6,5,4,7,8,9,8,7) c <- c("a","b","c","d","a","b","b","a","d","d") A <- cbind(a,b,c) test <- ftable(a,b,c) test.df <- data.frame(test) test.df[test.df$Freq != 0, ] Doesn't quite give the layout you seem to want, but effectively removes the ze

[R] tickmarks with time in dotplots

2010-02-22 Thread Mikkel Grum
Hi, I'm drawing lattice dotplots with time along the x-axis as in: C <-data.frame(c("A", "B"),Sys.time()+ rnorm(50)*3600) names(C) <- c("Name", "Time") dotplot(Name ~ Time, data = C, horizontal = TRUE) On my display, the x-axis shows tick marks every two hours. I would like to show something mo

[R] conout

2009-12-06 Thread Mikkel Grum
t from the NEWS files see what changed and much less what might work? Any ideas? *** Mikkel Grum +254 20 2345285 +254 720639599 (mobile) mikkelgrum (Skype) [[alternative HTML version deleted]] __ R-help@r-project.org maili

[R] rterm user command line input

2009-12-07 Thread Mikkel Grum
t from the NEWS files see what changed and much less what might work? Any ideas? *** Mikkel Grum +254 20 2345285 +254 720639599 (mobile) mikkelgrum (Skype) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-he

[R] RODBC not connecting from my Mac

2013-10-13 Thread Mikkel Grum
iODBC appears no longer to come standard with OSX, so I installed unixodbc and set it up following instructions here:  http://www.boriel.com/en/2013/01/16/postgresql-odbc-connection-from-mac-os-x/ I connected to my remote database with isql -v mydsn. No problem. Then I tried from R: > library(R

Re: [R] Loop over factor returns NA

2013-10-13 Thread Mikkel Grum
You'll need to tell us what class you time variable is in, e.g. the output of str(AB), but the following might work: for (i in unique(as.character(AB$time)) { Intervall <- AB[as.character(AB$time) ==i, ] ... } Depending on the format, as.numeric( ) might work too. Regards Mikkel On Saturday,

Re: [R] Looping over names of multiple data frames in an R for() loop XXXX

2013-10-13 Thread Mikkel Grum
You might want to try: assign(d[1], read.csv("yourfile.csv")) ... write.csv(d1, "yourfile.csv", append = FALSE) Regards Mikkel On Friday, October 11, 2013 2:53 PM, Dan Abner wrote: Hi everybody, I thought I was using the get() fn correctly here to loop over multiple data frame names in an

[R] RODBC on Mac

2013-10-13 Thread Mikkel Grum
iODBC appears no longer to come standard with OSX, so I installed unixodbc and set it up following instructions here:  http://www.boriel.com/en/2013/01/16/postgresql-odbc-connection-from-mac-os-x/ I connected to my remote database with isql -v mydsn. No problem. Then I tried from R: > library(R

Re: [R] Loop over factor returns NA

2013-10-13 Thread Mikkel Grum
You'll need to tell us what class you time variable is in, e.g. the output of str(AB), but the following might work: for (i in unique(as.character(AB$time)) { Intervall <- AB[as.character(AB$time) ==i, ] ... } Depending on the format, as.numeric( ) might work too. Regards Mikkel On Saturday, O

Re: [R] R plotting

2013-10-13 Thread Mikkel Grum
Hi This seems to work: spdata$color <- ifelse(spdata$change < 0, "red", "green") plot(spdata$date, log(spdata$close), col = spdata$color) Regards Mikkel On Friday, October 11, 2013 5:14 PM, Mubar wrote: Hi I have a question regarding plots in R. I have data from the S&P 500 in the format: d

[R] Saving long character variable to database saves timestamp instead

2010-09-18 Thread Mikkel Grum
LC_COLLATE=English_Ireland.1252 LC_CTYPE=English_Ireland.1252 [3] LC_MONETARY=English_Ireland.1252 LC_NUMERIC=C [5] LC_TIME=English_Ireland.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] RODBC_1.3-1Revob

[R] need for speed on grid.rect

2010-10-20 Thread Mikkel Grum
When I use grid.rect to print a multi-coloured grid, it is incredibly slow compared to a single colour grid, or even a two colour grid. I've set out some simplified examples below. This is something I run literally thousands of times a day, so I would greatly appreciate any hints on how I might

Re: [R] need for speed on grid.rect

2010-10-20 Thread Mikkel Grum
more data than the pdfs. I'm not sure to what extent the Windows graphics drivers affects the png and pdf drivers? Mikkel --- On Wed, 10/20/10, Paul Murrell wrote: > From: Paul Murrell > Subject: Re: [R] need for speed on grid.rect > To: "Mikkel Grum" > Cc: "

[R] batch file output

2010-12-28 Thread Mikkel Grum
I run a batch file with the following command in Windows XP: C:\R\R-2.12.1\bin\Rterm.exe --no-save --no-restore C:\users\me\file.out 2>&1 Is there any way to get only the output of R in file.out, without getting all the code from file.R too? Any help greatly appreciated, Mikkel _

Re: [R] batch file output

2010-12-28 Thread Mikkel Grum
gt; From: David Winsemius > Subject: Re: [R] batch file output > To: "David Winsemius" > Cc: "Mikkel Grum" , r-help@r-project.org > Date: Tuesday, December 28, 2010, 8:30 AM > > On Dec 28, 2010, at 8:27 AM, David Winsemius wrote: > > > > > On

Re: [R] Problem with combined two data frame.

2011-01-23 Thread Mikkel Grum
If you want all your NAs in the column GPAX to be 2.36, you could also say df2$GPAX[is.na(df2$GPAX)] <- 2.36 If you want only that specific NA to be 2.36, you are probably better off using df2$GPAX[rownames(df2) == 156] <- 2.36. --- On Sun, 1/23/11, Den wrote: > From: Den > Subject: Re: [R]

[R] INSERT OR UPDATE

2011-05-02 Thread Mikkel Grum
I'm trying to insert rows of a data.frame into a database table, or update where the key fields of a record already exist in the table. I've come up with a possible solution below, but would like to hear if anyone has a better solution. # The problem demonstrated: # Create a data.frame with tes

Re: [R] INSERT OR UPDATE

2011-05-02 Thread Mikkel Grum
RT OR UPDATE To: "Mikkel Grum" Cc: "R Help" Date: Monday, May 2, 2011, 5:15 PM Rather than selecting all the keys, then having R loop through them, why not have postgres do it for you with something like:   #go through each line in our entry table for (i in 1:dim(tbl)[1]){     #

[R] tryCatch?

2011-05-04 Thread Mikkel Grum
I would like to do inserts into a database table, but do updates in the fairly rare cases in which the inserts fail. I thought tryCatch might be the way to do it, but I honestly do not understand the help file for tryCatch at all. I thought something like this might work: for (i in seq(along = t

Re: [R] tryCatch?

2011-05-04 Thread Mikkel Grum
4/11, Prof Brian Ripley wrote: > From: Prof Brian Ripley > Subject: Re: [R] tryCatch? > To: "Mikkel Grum" > Cc: "R Help" > Date: Wednesday, May 4, 2011, 12:21 PM > Start with try(): you may find it > easier to understand. > > if(inherits(try(),

[R] Time and db precision

2011-05-25 Thread Mikkel Grum
I have a loop that regularly checks for new data to analyse in my database. In order to facilitate this, the database table has a timestamp column with the time that the data was inserted into the database. Something like this: while () { load(timetoken.Rdata) df <- sqlQuery(con, pas

Re: [R] Time and db precision

2011-05-26 Thread Mikkel Grum
uot; > d[d == max(as.POSIXct(d))] [1] "2011-05-25 22:15:11.027118000" > max(as.POSIXct(d)) [1] "2011-05-25 22:15:11 COT" --- On Thu, 5/26/11, Marc Schwartz wrote: > From: Marc Schwartz > Subject: Re: [R] Time and db precision > To: "Mikkel Grum&quo

[R] Pausing calculations for a fixed amount of time

2010-05-19 Thread Mikkel Grum
Is there any way to pause R for a gvien time period, i.e. without the need for user intervention? I've got a loop that I want to have work as hard as it can as long as there is data coming in, but when there is no new data, I would like it to pause before checking again. Something like in the follo

[R] process id of an R script

2011-09-07 Thread Mikkel Grum
I have a script that runs as a cron job every minute (on Ubuntu 10.10 and R 2.11.1), querying a database for new data. Most of the time it takes a few seconds to run, but once in while it takes more than a minute and the next run starts (on the same data) before the previous one has finished. In

[R] Superimposing titles on dotcharts

2011-09-12 Thread Mikkel Grum
I've created a chart with times that employees have entered data on named tasks as in the following example: Employee <- c(rep("Tom", 127),  rep("Dick", 121),  rep("Sally", 130) ) Time <- c(seq(as.POSIXct("2011-09-12 07:00:00"), as.POSIXct("2011-09-12 14:00:00"), 200), seq(as.POSIXct("2011-09-12

Re: [R] help with hclust and cutree

2011-09-13 Thread Mikkel Grum
plot(clust) rect.hclust(clust, h = 0.65) Is that what you wanted? - Original Message - From: Madeleine Seeland To: r-help@r-project.org Cc: Sent: Tuesday, September 13, 2011 9:25 AM Subject: [R] help with hclust and cutree Hello, I would like to cut a hclust tree into several groups

Re: [R] Deleting Rows based on Factor and Time Period

2011-09-13 Thread Mikkel Grum
The following will get you the first stock in each week. Is that useful? install.packages("surveillance") library(surveillance) alldat$year <- isoWeekYear(alldat$mydate)$ISOYear alldat$week <- isoWeekYear(alldat$mydate)$ISOWeek alldat <- alldat[order(alldat$year, alldat$week), ] alldat[!duplicated

Re: [R] Selecting row indices from a data.frame by a factor and simple calculation (miniumum)

2011-09-13 Thread Mikkel Grum
Code <- c(rep("NY14/3070", 3), rep("NY14/5459", 2)) Code <- as.factor(Code) absdiff <- c(2, 4, 1, 5, 7) df <- data.frame(Code, absdiff) which(     paste(df$Code, df$absdiff) ==      paste(         aggregate(df$absdiff, by = list(df$Code), min)$Group.1,         aggregate(df$absdiff, by = list(df$Cod

Re: [R] space in directory name

2011-09-13 Thread Mikkel Grum
You are missing \\ between Documents and settings and Administrator. - Original Message - From: dbonneau To: r-help@r-project.org Cc: Sent: Tuesday, September 13, 2011 10:59 AM Subject: [R] space in directory name Hi, I am trying to read a text file located in following paths. I am get

Re: [R] Deleting Rows based on Factor and Time Period

2011-09-14 Thread Mikkel Grum
alldat$yearmonth <- substr(alldat$mydate, 1, 7) From: Anna Dunietz Cc: "r-help@r-project.org" Sent: Wednesday, September 14, 2011 3:21 AM Subject: Re: [R] Deleting Rows based on Factor and Time Period Mikkel - thank you so much! That's a great start! I could

Re: [R] Image processing and analysis with R

2011-09-14 Thread Mikkel Grum
http://www.sciviews.org/zooimage/ might be useful. From: Jose Bustos Melo To: "r-help@r-project.org" Sent: Wednesday, September 14, 2011 4:06 PM Subject: [R] Image processing and analysis with R Hello everyone,  I'm working in a project to create an special

[R] axis.Date language

2012-07-08 Thread Mikkel Grum
Dear useRs I need to do graphs with dates in different languages on Ubuntu. In Windows the following will plot the date axis labels in Spanish: random.dates <- as.Date("2001/1/1") + 70*sort(stats::runif(100)) >language <- "Spanish" >Sys.setlocale("LC_TIME", language) >plot(random.dates, 1:100, x

Re: [R] axis.Date language

2012-07-09 Thread Mikkel Grum
Thanks Prof, I needed one more step on my system: sudo locale-gen es_ES.UTF-8 Mikkel From: Prof Brian Ripley Cc: R Help Sent: Monday, July 9, 2012 7:01 AM Subject: Re: [R] axis.Date language On 09/07/12 01:43, Mikkel Grum wrote: > Dear useRs > >

[R] truncated fields with RODBC

2007-11-24 Thread Mikkel Grum
I'm changing some functions from storing data in SQLite (using RSQLite) to storing it in PostgreSQL (using RODBC). When trying to store very long character fields I get the following message: >sqlSave(pg, Grids, rownames = FALSE, append = TRUE) Warning messages: 1: In odbcUpdate(channel, query

Re: [R] truncated fields with RODBC

2007-11-25 Thread Mikkel Grum
grDevices utils datasets methods base other attached packages: [1] RODBC_1.2-2 --- Prof Brian Ripley <[EMAIL PROTECTED]> wrote: > You need to study the RODBC documentation: you > haven't set the type of the > character fields in the database table corr

Re: [R] truncated fields with RODBC

2007-12-15 Thread Mikkel Grum
and what size of number I was looking for. cheers, Mikkel - Original Message From: Prof Brian Ripley <[EMAIL PROTECTED]> To: Mikkel Grum <[EMAIL PROTECTED]> Cc: [EMAIL PROTECTED] Sent: Sunday, November 25, 2007 2:05:37 PM Subject: Re: [R] truncated fields with RODBC

[R] Date formats

2007-12-29 Thread Mikkel Grum
Is the following expected behaviour for a date used in an ifelse function? > date <- Sys.Date() > date [1] "2007-12-30" > ifelse(TRUE, date-1, date) [1] 13876 > ifelse(FALSE, date-1, date) [1] 13877 > ifelse(TRUE, as.character(date-1), date) [1] "2007-12-29" > if (TRUE) {date} [1] "2007-12-30" It

Re: [R] Date formats

2007-12-30 Thread Mikkel Grum
, d, "1996-1-1") [[1]] [1] "1994-03-04" "1996-03-01" [[2]] [1] "1996-1-1" Any attempts to unlist, paste, etc. to remove the list structure converted/removed the Date class. Mikkel - Original Message From: Peter Dalgaard <[EMAIL PROTECTED]> To

[R] clipping viewports

2007-09-30 Thread Mikkel Grum
Dear useRs, Why are the rotated blue and yellow boxes in the example below clipped outside of 6 x 6 inch window in the middle of the page?? Where does the 6 x 6 inch window come from? I would like to make use of the entire page. > library(grid) > pdf(file = "FarmMaps.pdf", paper = "a4") > pushV

[R] How to avoid saving the row index of a data.frame into MySQL ?

2007-10-11 Thread Mikkel Grum
?dbWriteTable row.names = F Tonight's top picks. What will you watch tonight? Preview the hottest shows on Yahoo! TV. http://tv.yahoo.com/ __ R-help@r-pro