search for: jtor14

Displaying 19 results from an estimated 19 matches for "jtor14".

2011 Jun 17
3
rle on large data . . . without a for loop!
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)){ temp2<-temp+rle.dat$length[[i]] out$V1[i]<-mean(dat$V1[temp:temp2])
2011 May 31
2
count value changes in a column
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 acceptable as are changes from any value to 1 or 2. By way of an example: the sequence 1 3 3 5 5 3
2011 Mar 21
2
string interpolation
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? Thanks, justin
2011 Apr 27
3
MASS fitdistr with plyr or data.table?
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) weib.dist<-rweibull(10000,shape=3,scale=8) weib.test<-data.table(cbind(1:10,weib.dist))
2011 Jul 08
1
binary conversion list to data.frame with plyr... AND NO LOOPS!
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=""), "") my.dat<-c(36,40,10,4) my.binary.dat<-bb(my.dat)
2012 Apr 16
1
system command to a specific shell (bash)
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 CMD BATCH with "system" calls to other R scripts. For a little more info, I'm
2011 Aug 30
1
lubridate and intervals
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 the other two with rows where there were date overlaps.
2011 Oct 27
1
preceding X. and X
Hello, Why do I get preceding "X." (that is a and X followed by a period) for negative numbers and an "X" for positive numbers when I read a csv file? Am I stuck with this? If so, how do I convert it to normal numbers? dat=read.csv(file_path) > dat [1] X0.0 X.0.240432350374 X0.355468069625 X.0.211469972378 X1.1812797415 X.0.227975150826
2011 May 11
3
ddply with mean and max...
I'm trying to use ddply to compute summary statistics for many variables splitting on the variable site. however, it seems to work fine for mean() but if i use max() or min() things fall apart. whats going on? test.set<-data.frame(site=1:10,x=.Random.seed[1:100],y=rnorm(100)) means<-ddply(test.set,.(site),mean) means site x y 1 1 -97459496 -0.14826303 2
2011 Sep 12
1
plot 3 lines with ggplot2
Hi, I am trying to learn to use ggplot2 for what I had hoped would be a fairly simple task. I have a relatively small data.frame (100 by 4). The first column contains symbols. The 2nd, 3rd and 4th columns represent percentage weightings for each symbol using 3 different methodologies. For example: sym <- make.unique(replicate(100, paste(sample(LETTERS, 3, replace = TRUE), collapse =
2011 Aug 15
1
ggplot in a function confusion!
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. ## but if i wrap it in a function... plot.func.one<-function(dff,x.var,y.var){
2011 Aug 10
1
Sequential Naming of ggplot .pngs using plyr
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) print(ggplot(dat[,names(dat) %in%
2011 Mar 16
1
linear regression in a data.frame using recast
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 use recast somehow but I'm at a loss... how can I perform a simple linear regression (using
2011 Apr 23
0
MASS fitdistr call in plyr help!
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 y-axis = scale. Currently my code looks like: fit_wind_speed<-function(x){
2011 May 04
0
xtable without a loop alongside a ggplot
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. Any help is appreciated! set.seed(144) x=rnorm(100,mean=5,sd=1)
2011 May 13
0
How do I break my addiction to for loops!?!?
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
2011 Jun 03
0
ragged data.frame? using plyr
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...): adj.values<-function(dframe){ value_mean<-mean(dframe$value) value_sd<-sd(dframe$value)
2012 Jan 19
0
png output on a server?
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 fonts (specifically the size of the font). Adjusting the pointsize doesn't seem to have
2011 Nov 02
1
mysterious warning message regarding bytecode...
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 seem to affect my output as far as I can tell. Thanks! Justin > sessionInfo() R version