[R] system command to a specific shell (bash)

2012-04-16 Thread Justin Haynes
I need to run a bash command, but when you call system() the default shell is sh (see my sessionInfo below). I found the shell command ( http://www.stat.ucl.ac.be/ISdidactique/Rhelp/library/base/html/shell.html) but it seems to be disappeared in current versions of R? I am running all this from R

Re: [R] system command to a specific shell (bash)

2012-04-16 Thread Justin Haynes
Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Justin Haynes jto

Re: [R] A little exercise in R!

2012-04-14 Thread Justin Haynes
Since I thought this was a cool question, I posted it to StackOverflow. Vincent Zookynd's answer is amazing and really exercises the power of R. http://stackoverflow.com/questions/10150161/ordering-117-by-perfect-square-pairs/10150797#10150797 On Fri, Apr 13, 2012 at 10:06 PM, Bert Gunter

Re: [R] A little exercise in R!

2012-04-13 Thread Justin Haynes
I thought this was kinda cool! Here's my solution, its not robust or probably efficient I'd to hear improvements or other solutions! Justin sq.test - function(a, b) { ## test for number pairs that sum to squares. sqrt(sum(a, b)) == floor(sqrt(sum(a, b))) } ok.pairs - function(n, vec)

Re: [R] Remove carriage return in writing tab-delimited file.

2012-04-04 Thread Justin Haynes
take a look at ?paste paste(yourmatrix, sep='\t', collapse='') On Wed, Apr 4, 2012 at 2:58 PM, kickout plant.breeding.cr...@gmail.com wrote: Having problems with the write.table function. I can write a tab delimited file just fine, but for each line in my matrix its inputs a carriage return

Re: [R] sampling rows from a list

2012-04-02 Thread Justin Haynes
## recreating your data mydata-list(matrix(1:9, nrow=3, byrow=T), matrix(10:15, nrow=2, byrow=T), matrix(16:30, nrow=5, byrow=T)) ## get the shortest matrix in your list n - min(unlist(lapply(mydata, nrow))) ## subset the list into random samples of length n

Re: [R] list assignment syntax?

2012-03-30 Thread Justin Haynes
You can also take a look at http://stackoverflow.com/questions/7519790/assign-multiple-new-variables-in-a-single-line-in-r which has some additional solutions. On Fri, Mar 30, 2012 at 4:49 PM, Peter Ehlers ehl...@ucalgary.ca wrote: On 2012-03-30 15:40, ivo welch wrote: Dear R wizards:  is

Re: [R] scanning data into r

2012-03-28 Thread Justin Haynes
What have you tried? What type of file are you trying to import from? What do you want your data to look like in R? take a look at ?read.table and ?readLines On Wed, Mar 28, 2012 at 11:23 AM, joel.green joel.gr...@live.co.uk wrote: Hey I am having trouble importing data into R, my data

Re: [R] Why does this work? plyr within-subset normalization

2012-03-28 Thread Justin Haynes
To those without access to nabble, the code in reference is: relative - ddply(ranktable, .(Timestamp), function(x) data.frame(relative = x[,5]/max(x[,5]))) I may be misunderstanding your question, but: ddply splits your data.frame, ranktable, by the column Timestamp into many smaller

Re: [R] how to match exact phrase using gsub (or similar function)

2012-03-28 Thread Justin Haynes
In most regexs the carrot( ^ ) signifies the start of a line and the dollar sign ( $ ) signifies the end. gsub('^S S', 'S', a) gsub('^S S', 'S', '3421 BIGS St') you can use logical or inside your pattern too: gsub('^S S|S S$| S S ', 'S', a) the S S condition is difficult. gsub('^S S|S S$|

Re: [R] how to match exact phrase using gsub (or similar function)

2012-03-28 Thread Justin Haynes
Interstate 95, 3421 BIGS St)   gsub(\\S S\\, S, addresses)  [1] S Main St Interstate 95 3421 BIGS St Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Justin Haynes

Re: [R] Convert day of year back into a date format.

2012-03-27 Thread Justin Haynes
There may very well be a better solution, but this works. format(strptime(dayofyear, format=%j), format=%m-%d) On Tue, Mar 27, 2012 at 11:12 AM, Sam Albers tonightstheni...@gmail.comwrote: Hello, I am having trouble figuring out how to convert a Day of Year integer back into a Date format.

Re: [R] Remove a word from a character vector value XXXX

2012-03-07 Thread Justin Haynes
Hadley's package stringr is wonderful for all things string. library(stringr) ?str_trim and ?str_replace are what you want. (the base R equivalent of these two would be ?gsub and some regular expressions) str_trim(str_replace(d5.Region, 'Average', '')) should do the trick. hope that helps,

Re: [R] logical to vector?

2012-03-07 Thread Justin Haynes
?as.numeric as.numeric(c(TRUE, FALSE)) [1] 1 0 On Wed, Mar 7, 2012 at 8:02 AM, Ed Siefker ebs15...@gmail.com wrote: I am trying to use the coXpress function from the coXpress package.  This function requires numerical vectors indicating which columns are in which group. The problem is, I

Re: [R] GPS handling libraries or (String manipulation)

2012-03-07 Thread Justin Haynes
Take a look at: http://cran.r-project.org/web/views/Spatial.html But I've always just parsed the string... This is from the last time I did this, its not quite the same but you can see the similarities. ## if data is presented as 43°02'46.60059 N need to split on the ° symbol, ' and .

Re: [R] GPS handling libraries or (String manipulation)

2012-03-07 Thread Justin Haynes
Wow... that is WAY better! Thanks Gabor! On Wed, Mar 7, 2012 at 8:51 AM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Wed, Mar 7, 2012 at 11:28 AM, Alaios ala...@yahoo.com wrote: Dear all, I would like to ask you if R has a library that can work with different GPS formats For

Re: [R] regular expression

2012-02-29 Thread Justin Haynes
gsub('.+; (.+);.+','\\1',x) or if you just want the value out: gsub('.+; Surv\\(months\\): ([0-9]+);.+','\\1',x) You can also look at strsplit: strsplit(x,';') [[1]] [1] 99-625: Cell type: S Surv(months): 21 STATUS(0=alive, 1=dead): 1 lapply(strsplit(x,';'),'[',2) [[1]]

Re: [R] Problem building up ggplot graph in a loop.

2012-02-16 Thread Justin Haynes
ggplot is looking for thisData as a column of coffs. the most 'ggplotesque' way of doing this would be: # melt your data to a long format: coffs.melt - melt(coffs, id.vars = 'levels') # plot using colour aes parameter: ggplot(coffs.melt, aes(x=levels, y=value, colour=variable)) + geom_line() +

Re: [R] Change dataframe-structure

2012-02-13 Thread Justin Haynes
There is probably a more ellegant way, but: df - data.frame(p1=c(1,2,1),p2=c(3,3,2),p3=c(2,1,3),p4=c(5,6,4),p5=c(4,4,6),p6=c(6,5,5)) as.data.frame(t(apply(df,1,function(x) names(x)[match(1:6,x)]))) V1 V2 V3 V4 V5 V6 1 p1 p3 p2 p5 p4 p6 2 p3 p1 p2 p5 p6 p4 3 p1 p2 p3 p4 p6 p5 On Mon, Feb

Re: [R] debug in a loop

2012-02-10 Thread Justin Haynes
You can add if(is.na(tab[i])) browser() or if(is.na(tab[i])) break see inline On Fri, Feb 10, 2012 at 7:22 AM, ikuzar raz...@hotmail.fr wrote: Hi, I'd like to debug in a loop (using debug() and browser() etc but not print() ). I'am looking for the first occurence of NA. For instance:

Re: [R] Memory allocation problem (again!)

2012-02-08 Thread Justin Haynes
32 bit windows has a memory limit of 2GB. Upgrading to a computer thats less than 10 years old is the best path. But short of that, if you're just generating random data, why not do it in two or more pieces and combine them later? mat.1 - matrix(rnorm(5*2000),nrow=5) mat.2 -

Re: [R] Help need

2012-02-07 Thread Justin Haynes
Instead of a for loop, why not use the vectorization inherent in R? sigmasqaured - 1 i - complex(real = 0, imaginary =1) f - seq(0,0.5,0.1) spectrum - (sigmasqaured)/(abs(1-2.7607*exp(2*pi*i*f)+3.8106*exp(4*pi*i*f)-2.6535*exp(6*pi*i*f)+0.9258*exp(8*pi*i*f))^2) spectrum [1] 9.632720e+00

Re: [R] I bet apply has a solution

2012-02-06 Thread Justin Haynes
How bout: apply(Data..,1, function(vec) !all(vec==vec[1])) [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE On Mon, Feb 6, 2012 at 10:34 AM, LCOG1 jr...@lcog.org wrote: Hi all For the data below, I would like to return a logical value indicating differences in the data.

Re: [R] Select elements from text

2012-01-24 Thread Justin Haynes
how bout using read.table(... , sep= ). That would give you a vector of single words. then grepl(\\[[9-z]+\\],x) will return a boolean vector x-c('test','[bracket]','hi]','[blah','foo','[bar]') grepl('\\[[9-z]+\\]',x) [1] FALSE TRUE FALSE FALSE FALSE TRUE x[grepl('\\[[9-z]+\\]',x)] [1]

Re: [R] drop columns whose rows are all 0

2012-01-24 Thread Justin Haynes
dataset-data.frame(a=1:10,b=c(0,0,0,1,0,0,0,0,1,0),c=rep(0,10)) apply(dataset,2,function(x) all(x==0)) a b c FALSE FALSE TRUE dataset[,!apply(dataset,2,function(x) all(x==0))] a b 1 1 0 2 2 0 3 3 0 4 4 1 5 5 0 6 6 0 7 7 0 8 8 0 9 9 1 10 10 0 On Tue, Jan

Re: [R] How can I access information stored after I run a command in R?

2012-01-23 Thread Justin Haynes
?str tells you about the object. str(MAX3(a,'asy',1)) from that you can see the names of the various parts including p.value. foo - MAX3(a,'asy',1)$p.value On Mon, Jan 23, 2012 at 9:32 AM, Tiago V. Pereira tiago.pere...@mbe.bio.brwrote: Dear all, Supposed I run the following command:

Re: [R] colored outliers

2012-01-20 Thread Justin Haynes
TOC_NI-read.csv2(C:/Users/hilliges/Desktop/Master/Daten/Statistik/TOC-NI.csv, sep=;, dec=,, encoding=UTF-8) circ-TOC_NI[order(TOC_NI$NI,decreasing=T),][1:4,] plot(NI~TOC,data=TOC_NI,col=blue, pch=16, xlim=c(0,450)) abline(lm(NI~TOC,data=TOC_NI),col = red,lwd=3)

Re: [R] Stacked barchart in ggplot (or other library)

2012-01-20 Thread Justin Haynes
to use ggplot: dat-data.frame(num=1:3,usage=c(4,2,5),cap=c(10,20,10),diff=c(6,18,5)) dat.melt-melt(dat,id.var=c('num','cap')) ggplot(dat.melt)+geom_bar(aes(x=num,y=value,fill=variable),stat='identity') On Fri, Jan 20, 2012 at 12:30 PM, Jean V Adams jvad...@usgs.gov wrote: Bart6114 wrote on

Re: [R] Establishing groups using something other than ifelse()

2012-01-19 Thread Justin Haynes
how bout levels(df$z)[grep('A',levels(df$z))] - 'A' levels(df$z)[grep('B',levels(df$z))] - 'B' levels(df$z)[grep('C',levels(df$z))] - 'C' does that do what you're wanting? On Thu, Jan 19, 2012 at 3:05 PM, Sam Albers tonightstheni...@gmail.comwrote: Hello all, This is one of those Is there

[R] png output on a server?

2012-01-18 Thread Justin Haynes
I've got R running on a gentoo server that doesn't have X11 installed. Its a custom build to keep those dependencies at bay! However, some of my scripts use the base png() function and ggplot2. But, png uses X11. A google search suggests using the Cairo package, which works... but changes the

Re: [R] Points inside a polygon

2012-01-12 Thread Justin Haynes
On Wed 11 Jan 2012 08:28:03 PM PST, Hasan Diwan wrote: I have a list of bounds for a series of polygons. I do understand the formula to determine whether point i is within polygon X (X[x1] i[x] X[x2] i[x] X[y1] i[y] X[y2] i[y]), and I can apply this throughout the dataset. However, this

Re: [R] relative frequency plot using ggplot or other function

2012-01-12 Thread Justin Haynes
On Thu 12 Jan 2012 09:02:27 AM PST, Mary Kindall wrote: Hi I have a data frame in the following form. There are two groups and for each 'width' relative frequency for group1 and group2 is given. How to plot this in R using ggplot or other package. Width relativeFrequency1

Re: [R] relative frequency plot using ggplot or other function

2012-01-12 Thread Justin Haynes
the legends of the following fig. http://had.co.nz/ggplot2/graphics/55078149a733dd1a0b42a57faf847036.png http://had.co.nz/ggplot2/graphics/90983232ced45a93d9fbbe40afffd69a.png Thanks On Thu, Jan 12, 2012 at 12:13 PM, Justin Haynes jto...@gmail.com wrote: On Thu 12 Jan 2012 09:02:27 AM

Re: [R] Add color to Boxplot by value

2012-01-12 Thread Justin Haynes
how bout: dat-data.frame(val=rnorm(100,12,10),x=letters[1:4]) col.val-ddply(dat,.(x),summarise,mean(val)) col.val$breaks-cut(col.val$..1,c(0,9,15,Inf)) dat.merge-merge(dat,col.val) ggplot(dat.merge,aes(x=x,y=val,colour=breaks))+geom_boxplot()+scale_color_manual(values=c('green','yellow','red'))

Re: [R] colored outliers

2012-01-10 Thread Justin Haynes
# find top 4 points circ - TOC_NI[order(TOC_NI$NI,decreasing=T),][1:4,]TOC_NI[order(TOC_NI$NI,decreasing=T),][1:4,] # add them to your plot! plot(NI~TOC,data=TOC_NI,col=blue, pch=16, xlim=c(0,450)) abline(lm(NI~TOC,data=TOC_NI),col = red,lwd=3)

Re: [R] colored outliers

2012-01-10 Thread Justin Haynes
woops! see inline. Hope that helps, and enjoy R. Justin On Tue, Jan 10, 2012 at 8:40 AM, Geophagus falk.hilli...@twain-systems.comwrote: Hi Justin, thanks a lot for your quick answer. If I use your code, all points become red. How do you include the sorted and separated four values into

Re: [R] match matrices of different lengths

2012-01-05 Thread Justin Haynes
see ?merge merge(xx,aa,by.x='x',by.y='a') x y b 1 2.00112e+11 1.0 1.2 2 2.00112e+11 1.1 1.9 making the two matricies time series does not mean that R knows that the first column is a datetime. and depending on your desired result, that may not be important. hope that helps,

Re: [R] ggplot2 - tricky problem

2012-01-05 Thread Justin Haynes
how bout: dat-data.frame(id=1:4,city=c('berlin','munich'),likeability=c(5,4,6,5),uniqueness=c(3,4,4,4)) ggplot(ddply(melt(dat, id.vars=c('id','city')), .(variable,city), summarise, value=mean(value)),

Re: [R] [newbie] stack operations, or functions with side effects (or both)

2012-01-04 Thread Justin Haynes
do s[1] and s[-1] do what you're looking for? those are just to display... if you want to change s, you need to reassign it or fiddle with namespacing. however, I'd say it is better to write R code as though data structures are immutable until you explicitly re-assign them rather than trying to

Re: [R] Combining characters

2012-01-04 Thread Justin Haynes
apply(expand.grid(x, y, z, stringsAsFactors=F), 1, paste, collapse=' ') On Wed, Jan 4, 2012 at 8:32 AM, jeremy jeremynamer...@gmail.com wrote: Hi all, I'm trying to combine exhaustively several character arrays in R like: x=c(one,two,three) y=c(yellow,blue,green) z=c(apple,cheese) in

Re: [R] a quick question about rbinom

2012-01-04 Thread Justin Haynes
homework or not, ?rbinom should be plenty. On Wed, Jan 4, 2012 at 1:38 PM, lynn.tsai vernal@gmail.com wrote: Hello, I have the following code using rbinom, but I don't understand what *+1* means in the code. Could someone help? Thanks so much, X1-c(A,B)[rbinom(n,1,0.6)+1]

Re: [R] Applyiing mode() or class() to each column of a data.frame XXXX

2011-12-30 Thread Justin Haynes
there is also colwise in the plyr package. library(plyr) colwise(class)(data6) v13 v14 v15 f4 v16 1 integer numeric character factor logical Justin On Thu, Dec 29, 2011 at 4:47 PM, Jean V Adams jvad...@usgs.gov wrote: Dan Abner wrote on 12/29/2011 06:13:11 PM:

Re: [R] Help with code

2011-12-20 Thread Justin Haynes
the short answer... which is a guess cause you didn't provide a reproducible example... is: your column (i think its called t1d_ptype[1:25]) is a factor and using factors is dangerous at best. you can check with ?str. see ?factor for how to convert back to strings and see if your code works.

Re: [R] Help with code

2011-12-20 Thread Justin Haynes
Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Justin Haynes Sent: Tuesday, December 20, 2011 11:54 AM To: 1Rnwb Cc: r-help@r-project.org Subject: Re: [R] Help with code the short

Re: [R] how to manually enter an double quote as data feed?

2011-12-13 Thread Justin Haynes
\ is how its displayed on the screen. however, if you write your object to a csv it will be correct. r cant display as it is so it is escaping the second double quote for you however, ' (double quote single quote double quote) does display correctly as well as save correctly. If that doesn't

Re: [R] using sample

2011-12-07 Thread Justin Haynes
Emma, If you haven't spent much time on the r-help forums, please do read the posting guide. You need to provide reproducible examples for us to help you. We don't know anything about your data... what is event.details, (if you can't provide the data often ?str will do) since I don't know

Re: [R] hour in x-axis

2011-11-29 Thread Justin Haynes
without knowing much about your data or the base plotting... I'd use the library ggplot2. First, you'll need to format your dates to POSIXct AggData$time - as.POSIXct(AggData$time,format='%H:%M') Then plotting is trivial. ggplot(AggData,aes(x=time,y=value))+geom_points() or +geom_line() if

Re: [R] aggregate syntax for grouped column means

2011-11-29 Thread Justin Haynes
look at just your data that is in that first id category and I bet you can figure it out! myData[myData$id=='0m11',] var1 var2 id 10 30.79 32.15 0m11 11 30.79 32.39 0m11 12 30.94NA 0m11 aggregate performs the na.rm step on the entire row thus, a mean of 30.79. data.table and plyr

Re: [R] tip: large plots

2011-11-18 Thread Justin Haynes
Very cool. Sadly, as far as I can tell, it doesn't work with ggplot though :( x-runif(1e6) y-runif(1e6) system.time(plot(x,y,pch='.')) user system elapsed 0.824 0.012 0.845 system.time(plot(x,y)) user system elapsed 33.422 0.016 33.545 system.time(print(qplot(x,y)))

Re: [R] tip: large plots

2011-11-18 Thread Justin Haynes
(qplot(x,y,pch=I('.' user system elapsed 32.370 0.204 33.868 On Fri, Nov 18, 2011 at 12:39 PM, Hadley Wickham had...@rice.edu wrote: You need: system.time(print(qplot(x,y,pch=I('.' Hadley On Fri, Nov 18, 2011 at 1:30 PM, Justin Haynes jto...@gmail.com wrote: Very cool

Re: [R] apply on rows and columns?

2011-11-16 Thread Justin Haynes
To expand on what Sarah and Michael said: if you have a 3d array: x-array(1:4,c(2,2,4)) x , , 1 [,1] [,2] [1,]13 [2,]24 , , 2 [,1] [,2] [1,]13 [2,]24 , , 3 [,1] [,2] [1,]13 [2,]24 , , 4 [,1] [,2] [1,]13 [2,]

Re: [R] Extract pattern from string

2011-11-15 Thread Justin Haynes
take a look at the structure of what Sys.time returns. str(Sys.time) and now at ?strptime! format(Sys.time(),format='%d-%H-%M-%S') [1] 15-09-55-55 format(Sys.time(),format='%Y') [1] 2011 format(Sys.time(),format='%m') [1] 11 Hope that helps, Justin On Tue, Nov 15, 2011 at 9:48 AM,

Re: [R] Create design matrix

2011-11-03 Thread Justin Haynes
?expand.grid expand.grid(c(M,F),c(Y,O)) Var1 Var2 1MY 2FY 3MO 4FO Justin On Thu, Nov 3, 2011 at 10:56 AM, Bond, Stephen stephen.b...@cibc.com wrote: Greetings useRs, What is the easiest way to create a design matrix of several factor variables? Function

[R] mysterious warning message regarding bytecode...

2011-11-02 Thread Justin Haynes
While running a long script which source()s other scripts I get the following warning: Warning message: In t(object$S[[1]]) : bytecode version mismatch; using eval I cannot replicate it if I run the sourced files line by line though... What is that error? And do I care about it? It doesn't

Re: [R] factor level issue after subsetting

2011-11-01 Thread Justin Haynes
first of all, the subsetting line is overly complicated. dat.sub-dat[dat$treat!='cont',] will work just fine. R does exactly what you're describing. It knows the levels of the factor. Once you remove 'cont' from the data, that doesn't mean that the level is removed from the factor:

Re: [R] reshape2: Lost Values Between melt() and dcast()

2011-10-31 Thread Justin Haynes
The reason dcast would give that warning (not a failure) is if the formula you gave did not specify unique values. Thus, dcast needs an aggregating function, which defaults to length. However, the dcast calls that failed can be helpful for determining the source of your error. I'd look at the

Re: [R] Replacing matching values by related values

2011-09-18 Thread Justin Haynes
in your assignment for t3 you use nt which is undefined. thus t.n$treatment is NAs but: df-data.frame(num=1:10,let=letters[1:10]) dat-data.frame(let=sample(letters[1:10],20,replace=T)) dat$matched-df$num[match(dat$let,df$let)] should get you started On Sun, Sep 18, 2011 at 7:56 AM, Janssen,

Re: [R] R shell line width

2011-09-16 Thread Justin Haynes
you want options(width= ) you can edit your .Rprofile file and the .First function in there to set it when you start R or in the console interactively On Fri, Sep 16, 2011 at 12:48 PM, Mike P mike.polya...@gmail.com wrote: Hi, I want to apologize in advance if this has already been asked. I

Re: [R] map

2011-09-13 Thread Justin Haynes
i responded offline the first time, but: google is your friend: search for R maps and you'll find what I mention below. In the future make sure to perform a thorough search of google and the help forums before you post That said... you're looking for the maps package install.packages('maps')

Re: [R] reshaping data

2011-09-07 Thread Justin Haynes
look at the melt function in reshape, specifically ?melt.data.frame require(reshape) Raw.melt-melt(RawData,id.vars='Year',variable_name='Month') there is an additional feature in the melt function for handling na values. names(Raw.melt)[3]-'CO2' head(Raw.melt) Year MonthCO2 1 1958 J

Re: [R] Fitting my data to a Weibull model

2011-08-31 Thread Justin Haynes
This is what I use... fit.func-function(x){ require(MASS) est-fitdistr(x$wind_speed, 'weibull')$estimate data.frame(shape=est[1],scale=est[2]) } feel free to correct me if this is wrong! Justin On Wed, Aug 31, 2011 at 6:21 AM, Dennis Murphy djmu...@gmail.com wrote: Hi: Things work

[R] lubridate and intervals

2011-08-30 Thread Justin Haynes
Hiya, maybe there is a native R function for this and if so please let me know! I have 2 data.frames with start and end dates, they read in as strings and I am converting to POSIXct. How can I check for overlap? The end result ideally will be a single data.frame containing all the columns of

Re: [R] how to referee a dimension name via a variable?

2011-08-29 Thread Justin Haynes
try: newnam-paste('newdatadat',dayno,sep='') plot(test[[newnam[1]]]) On Mon, Aug 29, 2011 at 12:29 PM, Jie TANG totang...@gmail.com wrote: hi, R-users I have a data.frame for example test$newdataday24 and test$newdataday48 I can plot them by plot(test$newdataday24) but now i want to

Re: [R] debugging functions in R

2011-08-24 Thread Justin Haynes
Another great tool is debugonce() wrap your function name in it and then execute your function call. debugonce(my.function) out-my.function(df) And you'll be brought into the same interactive browser. (its Vi if im not mistaken which can take a little getting used to.) Justin On Wed, Aug

Re: [R] as.numeric() and POSIXct format

2011-08-24 Thread Justin Haynes
as.POSIXct(518400,origin='2001-01-01') [1] 2001-01-07 PST as.POSIXct(as.numeric(as.POSIXct(518400,origin='2001-01-01')),origin='1970-01-01') [1] 2001-01-07 08:00:00 PST On Wed, Aug 24, 2011 at 9:22 AM, Agustin Lobo agustin.l...@ija.csic.eswrote: Hi! I'm confused by this:

Re: [R] subsetting a list of matrices

2011-08-23 Thread Justin Haynes
His is better, but you can also use a for loop... out-data.frame(rows=1:3) for(i in 1:3){ if(l[[i]][3]=='Message 1') { out$V1[i]-l[[i]][1] } else { out$V1[i]-NA } } but shouldn't if your list is very long On Tue, Aug 23, 2011 at 9:35 AM, Henrique Dallazuanna www...@gmail.comwrote:

Re: [R] ddply - how to transform df column in place

2011-08-23 Thread Justin Haynes
Jean, Ista is right, but: In your function you are asking as.Date to convert the whole data.frame df rather than just your daterep column. out-ddply(d2, .(daterep), function(df) as.Date(strptime(df$daterep,format='%Y%m%d'))) str(out) 'data.frame':30 obs. of 2 variables: $ daterep: num

Re: [R] Help: Sort components of a vector with indices tracked in R

2011-08-23 Thread Justin Haynes
If you make your vector a data.frame, you will have row numbers accompanying your sorting df-data.frame(V1=c(1,4,3,2)) df$rows-row.names(df) df[order(df$V1),] also, you shouldn't use c as a variable name since its an important R function... see your example :) Justin On Tue, Aug 23, 2011 at

[R] ggplot in a function confusion!

2011-08-15 Thread Justin Haynes
Whats going on here? df-data.frame(x=1:10,y=1:10) ggplot()+geom_point(data=df,aes(x=x,y=y)) ## this is the normal usage right? ggplot()+geom_point(data=df,aes(x=df[,1],y=df[,2])) ## but I can also feed it column indices ggplot()+geom_point(aes(x=df[,'x'],y=df[,'y'])) ## or column names. ##

[R] Sequential Naming of ggplot .pngs using plyr

2011-08-10 Thread Justin Haynes
If I have data: dat-data.frame(a=rnorm(20),b=rnorm(20),c=rnorm(20),d=rnorm(20),site=rep(letters[5:8],each=5)) And want to plot like this: ctr-1 for(i in c('a','b','c','d')){ png(file=paste('/tmp/plot_number_',ctr,'.png',sep=''),height=8.5, width=11,units='in',pointsize=9,res=300)

Re: [R] Sequential Naming of ggplot .pngs using plyr

2011-08-10 Thread Justin Haynes
like an excessive extra step when I have 1e6 - 1e7 rows. Justin On Wed, Aug 10, 2011 at 2:42 PM, Ista Zahn iz...@psych.rochester.eduwrote: Hi Justin, On Wed, Aug 10, 2011 at 5:04 PM, Justin Haynes jto...@gmail.com wrote: If I have data: dat-data.frame(a=rnorm(20),b=rnorm(20),c=rnorm(20

[R] binary conversion list to data.frame with plyr... AND NO LOOPS!

2011-07-08 Thread Justin Haynes
Happy weekend helpeRs! As usual, I'm stumped by R... My plan was to take an integer number, convert it to binary and wind up with a data.frame where each column is either 1 or 0 so I can see which bits are changing: bb-function(i) ifelse(i, paste(bb(i %/% 2), i %% 2, sep=), )

[R] rle with NA values?

2011-06-24 Thread Justin Haynes
Happy Friday! Using this function: fixSeq - function(df) { shift1 - function(x) c(1, x[-length(x)]) df$state_shift-df$state df.rle-rle(df$state_shift) repeat { shifted.sf-shift1(df.rle$values) change - df.rle$values = 4 shifted.sf = 4 shifted.sf != df.rle$values

[R] rle on large data . . . without a for loop!

2011-06-17 Thread Justin Haynes
I think need to do something like this: dat-data.frame(state=sample(id=rep(1:5,each=200),1:3, 1000, replace=T,prob=c(0.7,0.05,0.25)),V1=runif(1,10,1000),V2=rnorm(1000)) rle.dat-rle(dat$state) temp-1 out-data.frame(id=1:length(rle.dat$length)) for(i in 1:length(rle.dat$length)){

[R] gridExtra with cairodevie and ggplots

2011-06-14 Thread Justin Haynes
I apologise in advance for not providing code, but this seems like a straight forward question... I am making a few full page plots some of which are portrait and some of which are landscape I would like to open my cairo device once and put all the plots in the same .pdf. But since some need to

Re: [R] gridExtra with cairodevie and ggplots

2011-06-14 Thread Justin Haynes
)) HTH, baptiste On 15 June 2011 08:39, Justin Haynes jto...@gmail.com wrote: I apologise in advance for not providing code, but this seems like a straight forward question... I am making a few full page plots some of which are portrait and some of which are landscape I would like to open my

[R] ragged data.frame? using plyr

2011-06-02 Thread Justin Haynes
I have a dataset that looks like: set.seed(144) sam-sample(1000,100) dat-data.frame(id=letters[1:10],value=rnorm(1000),day=c(rep(1,100),rep(2,100),rep(3,100),rep(4,100),rep(5,100))) I want to normalise it using the following function (unless you have a better idea...):

[R] count value changes in a column

2011-05-31 Thread Justin Haynes
is there a way to look for value changes in a column? set.seed(144) df-data.frame(state=sample(rep(1:5,200),1000)) any of the five states are acceptable. however if, for example, states 4 or 5 follow state 3, i want to overwrite them with 3. changes from 1 to any value and 2 to any value are

Re: [R] count value changes in a column

2011-05-31 Thread Justin Haynes
I apologize for the confusion but that solution will work with a twist. I want to record only the first value of a state change that goes above 2. so if the sequence is 344455544334 it should read all 3s but 3442555414433 should read 33321 Hope that helps clarify, if not I can get

[R] ggplot geom_boxplot vertical margins

2011-05-18 Thread Justin Haynes
If you plot: df-data.frame(x=factor(1:100),y=rnorm(1000)) ggplot(df,aes(x=x,y=y))+geom_boxplot() How do I remove those pesky margins on the sides of the plot area? Or maybe just reduce their size to something more like the spacing of the boxes? Thanks, Justin

Re: [R] ggplot geom_boxplot vertical margins

2011-05-18 Thread Justin Haynes
))+geom_boxplot() + scale_x_discrete(expand=c(0,0)) Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish Wildlife Service California, USA http://www.fws.gov/redbluff/rbdd_jsmp.aspx - Original Message From: Justin Haynes jto...@gmail.com To: r

[R] How do I break my addiction to for loops!?!?

2011-05-13 Thread Justin Haynes
I know I'm not supposed to use them... but they're just so easy! I have trouble defining an appropriate function for plyr or apply! data-rnorm(144) groups1-c('a','b','c','d') groups2-c('aa','bb','cc','dd') machines-1:12

[R] xtable without a loop alongside a ggplot

2011-05-04 Thread Justin Haynes
I would like to create a table of my points and identify which 'quadrant' of a plot they are in with the 'origin' at the means. the kicker is i would like to display it right next to or below a ggplot of the data. Maybe xtable isnt the right thing to use, but its the only thing i can think of.

[R] MASS fitdistr with plyr or data.table?

2011-04-27 Thread Justin Haynes
I am trying to extract the shape and scale parameters of a wind speed distribution for different sites. I can do this in a clunky way, but I was hoping to find a way using data.table or plyr. However, when I try I am met with the following: set.seed(144)

[R] MASS fitdistr call in plyr help!

2011-04-22 Thread Justin Haynes
I have a set of wind speeds read at different locations. The data is a data frame with two columns: site and wind speed. I want to split the data on site and call a function to find the shape and scale parameters of a weibull distribution fit. The end result is a plot with x-axis = shape and

[R] string interpolation

2011-03-21 Thread Justin Haynes
Is there a way to do this in R? I have data in the form: 57_input 57_output 58_input 58_output etc. can i use a for loop (i in 57:n) that plots only the outputs? I want this to be robust so im not specifying a column id but rather something like c++ code, %s_input, i is that doable in R?

[R] linear regression in a data.frame using recast

2011-03-16 Thread Justin Haynes
I have a very large dataset with columns of id number, actual value, predicted value. This used to be a time series but I have dropped the time component. So I now have a data.frame where the id number is repeated but each value in the actual and predicted columns are unique. I assume I need to