Re: [R] Job scheduling in R

2010-11-19 Thread Jeffrey Spies
Cron still works, but launchd/launchctl seems to be preferred by some if you're on Mac OS X. J. On Fri, Nov 19, 2010 at 7:09 PM, Steve Lianoglou wrote: > Hi, > > On Fri, Nov 19, 2010 at 10:09 AM, amit jain wrote: >> Hi All, >> >> Can anyone point to any package/resouce to schedule a job in R wh

Re: [R] assignment operator saving factor level as number

2010-11-05 Thread Jeffrey Spies
e. > > Wade > > On Fri, Nov 5, 2010 at 4:12 PM, Jeffrey Spies wrote: >> >> Perhaps this will help: >> >> > test1 <- test2 <- data.frame(col1=factor(c(1:3), labels=c("a", "b", >> > "c"))) >> > test3 <-

Re: [R] assignment operator saving factor level as number

2010-11-05 Thread Jeffrey Spies
Perhaps this will help: > test1 <- test2 <- data.frame(col1=factor(c(1:3), labels=c("a", "b", "c"))) > test3 <- data.frame(col1 = 1:3) Now: > test2[2,1] <- test1$col1[1] > test2$col1 [1] a a c Levels: a b c vs > test3[2,1] <- test1$col1[1] > test3$col1 [1] 1 1 3 Because test3's first column,

Re: [R] parallel for loop

2010-10-31 Thread Jeffrey Spies
Take a look at the parallel computing section of: http://cran.r-project.org/web/views/HighPerformanceComputing.html specifically the line concerning the foreach package. Jeff. On Sun, Oct 31, 2010 at 6:38 PM, wrote: > > Hi all, > > Just following on from a previous thread (for loop). Is there

[R] ggplot2: how to label lines?

2010-10-25 Thread Jeffrey Spies
Hi, all, Let's say I have some time series data--10 subjects measured 20 times--that I plot as follows: library(ggplot2) dat <- data.frame(subject=as.factor(rep(1:10, each=20)), time=rep(1:20, 10), measure=as.vector(replicate(10, rnorm(20, mean=runif(1, 0, 15), sd=runif(1, 1, 3) p <- qplot(ti

Re: [R] Text wrapping in R

2010-10-24 Thread Jeffrey Spies
I would demonstrate one of the many LaTeX table functions. Off hand, packages xtable, hmisc, and quantreg all have functions that convert R objects to LaTeX tables. If they're unwilling to work in LaTeX, you can use something like LaTeXiT or Laeqed to create PDFs or PNGs of the tables for inserti

Re: [R] Help reading table rows into lists

2010-10-10 Thread Jeffrey Spies
To get just the list you wanted, Gabor's solution is more elegant, but here's another using the apply family. First, your data: dat <- scan(file="/g/bork8/waller/test_COGtoPath.txt",what="character",sep="\n") I expect dat to be a vector of strings where each string is a line of values separated

Re: [R] StrSplit

2010-10-09 Thread Jeffrey Spies
ying, Jeff. On Sat, Oct 9, 2010 at 1:04 PM, David Winsemius wrote: > > On Oct 9, 2010, at 12:46 PM, Jeffrey Spies wrote: > >> Jim's solution is the ideal way to read in the data: using the sep=";" >> argument in read.table. >> >> However, if y

Re: [R] Counting unique items in a list of matrices

2010-10-09 Thread Jeffrey Spies
If you just want a list of matrices and their counts, you can use Peter's list of matrices, L, and then: With plyr: require(plyr) count(unlist(lapply(L, toString))) Without plyr: as.data.frame(table(unlist(lapply(L, toString Cheers, Jeff. On Sat, Oct 9, 2010 at 12:44 PM, Peter Ehlers wr

Re: [R] StrSplit

2010-10-09 Thread Jeffrey Spies
Jim's solution is the ideal way to read in the data: using the sep=";" argument in read.table. However, if you do for some reason have a vector of strings like the following (maybe someone gives you an Rdata file instead of the raw data file): MF_Data <- c("106506;AIG India Liquid Fund-Institutio

Re: [R] function using values separated by a comma

2010-10-08 Thread Jeffrey Spies
Here's another method without using any external regular expression libraries: dat <- read.table(tc <- textConnection( '0,1 1,3 40,10 0,0 20,5 4,2 10,40 10,0 0,11 1,2 120,10 0,0'), sep="") mat <- apply(dat, c(1,2), function(x){ temp <- as.numeric(unlist(strsplit(x, ','))) min(temp

Re: [R] R: Tools for thinking about data analysis and graphics

2010-10-06 Thread Jeffrey Spies
Hi, Michael, When I teach/preach on R, I emphasize the language's focus on data, both in its objects and operations. It might seems basic, but it's fundamental to most of the features you and others have mentioned. As a statistical programming language, what we intend to do with R is often very na

Re: [R] Empty data frame does not maintain column type

2010-10-06 Thread Jeffrey Spies
This should do it: df <- data.frame(a=character(0), b=character(0), stringsAsFactors=F) because: typeof(factor(0)) is "integer" while: typeof(character(0)) is "character". Cheers, Jeff. On Wed, Oct 6, 2010 at 1:00 PM, N David Brown wrote: > Does anyone know why a data frame created with

Re: [R] Create variable by name

2010-10-06 Thread Jeffrey Spies
An alternative to Peter's solution: createVariable <- function(name) {assign(name, NULL, envir=.GlobalEnv)} Jeff. On Wed, Oct 6, 2010 at 12:32 PM, Ralf B wrote: > Can one create a variable through a function by name > > createVariable <- function(name) { >        outputVariable = name >        

Re: [R] Sampling from data set

2010-10-05 Thread Jeffrey Spies
sample(1:1,100),])". > Now it include all 2 variable. > Thank you for your answer to inspire. > Jumlong > > 2010/10/5 Jeffrey Spies >> >> We'll probably need much more info, but this should get you started: >> >> nameOfDataSet[sample(1:1,

Re: [R] Sampling from data set

2010-10-05 Thread Jeffrey Spies
We'll probably need much more info, but this should get you started: nameOfDataSet[sample(1:1, 100),] You can replace the 1 with dim(nameOfDataSet)[1] to make it more dynamic. Jeff. On Tue, Oct 5, 2010 at 3:07 AM, Jumlong Vongprasert wrote: > Dear all. > I have data with 2 variable x,y

Re: [R] R-help

2010-10-04 Thread Jeffrey Spies
As Joshua said, in your example sim isn't be declared anywhere (neither in the environment nor as an argument in a function), but you might try something more R-ish: prop.doubles <- function(sim){ sum(sample(1:6, sim,replace=T)==sample(1:6,sim,replace=T))/sim } prop.doubles(1000) Cheers, Jef

Re: [R] For help on Open .tar.gz file in R under Windows

2010-10-04 Thread Jeffrey Spies
read.table('path.to.file.tar.gz') or any of its derivatives (read.csv, read.csv2, etc.). Of course you'll need to set the arguments appropriately. For example: read.table('path.to.comma.delimited.tar.gz', sep=",", header=T) Cheers, Jeff. On Mon, Oct 4, 2010 at 6:48 PM, wenyue sun wrote: > Hey

Re: [R] can't find and install reshape2??

2010-10-03 Thread Jeffrey Spies
The first argument in download.packages should be of type character or a vector of characters. This worked for me: install.packages('reshape2') as did: download.packages('reshape2', '~/Downloads/') Cheers, Jeff. On Sun, Oct 3, 2010 at 8:57 PM, Chris Howden wrote: > Hi everyone, > > > > I’m

Re: [R] Ranked Set Sampling

2010-10-03 Thread Jeffrey Spies
This is certainly not my area of expertise, but like Peter mentioned, Jeff Terpstra published this: http://www.jstatsoft.org/v14/i07 which has R code listed as supplements. Joe McKean seems to keep an updated version of that code here: http://www.stat.wmich.edu/red5328/WWest/ And Brent Johnson

Re: [R] A problem about nomogram--thank you for you help

2010-10-03 Thread Jeffrey Spies
Firstly, `*` is the multiplication operator in R. Secondly, you'll need to convert your factors to numerics: L<-0.559*as.numeric(T.Grade)-0.896*as.numeric(Smoking)+0.92*as.numeric(Sex)-1.338 Cheers, Jeff. 2010/10/3 笑啸 : > dear professor: > I am a doctor of urinary,and I am developing a nomogra

Re: [R] Modifying a data.frame

2010-10-03 Thread Jeffrey Spies
You should examine what is being looped over when you use a for loop with the "i in dataframe" syntax: j<-1; for(i in ex){ cat('step', j, i, sep=" ", fill=T); j<-j+1} As you can see, each column in ex is being set to i for each step of the for loop. Instead, it seems that you want to step over e

Re: [R] R data opening problem

2010-10-02 Thread Jeffrey Spies
If I understand your problem correctly, I think you need to be doing: summary(data.name) The functions read.dta and read.spss both return things (data frames, if you use the to.data.frame=T argument with read.spss). So whatever variable you set is what you should be doing a summary on. In this

Re: [R] [Help]:How to use "loop" to achieve this aim?

2010-10-01 Thread Jeffrey Spies
Correcting Karena's solution: for(i in 1:22) { chrn <- paste("chr",i,sep="") chrn=MEDIPS.readAlignedSeqences(BSgenome="hg19", file=chrn,numrows= ?) # no quotes around chrn chrn=MEDIPS.genomeVector(data=chrn, bin_size=50,extend=250) frames=? # I don't know how you get this variable ... ou

Re: [R] Need to incorporate the use of na.rm into custom function

2010-10-01 Thread Jeffrey Spies
You can use na.omit on x after it is passed into your apply function if na.rm == T, or simply pass your na.rm to functions that use it, such as sum. Hope that helps, Jeff. On Fri, Oct 1, 2010 at 11:07 AM, Ochsner, Scott A wrote: > Hi, > > Take a matrix with missing values: > >> X = matrix(rnorm

[R] LR Decomposition?

2008-06-23 Thread Jeffrey Spies
Hi all, Is there an LR decomposition function in R and, if not, how can we get the non-compact representation of Q from QR decomposition? Thanks, Jeff. -- View this message in context: http://www.nabble.com/LR-Decomposition--tp18072588p18072588.html Sent from the R help mailing list archive a

Re: [R] S4 pass-by-value work-around?

2008-06-19 Thread Jeffrey Spies
niqueCount<-")) > > setReplaceMethod("uniqueCount", > signature=c(x="MyMatrix", value="numeric"), > function(x, ..., value) { > [EMAIL PROTECTED] <- value > x > }) > > uniqueCount(x) <- uniqueCount(x)

[R] S4 pass-by-value work-around?

2008-06-18 Thread Jeffrey Spies
Howdy all, I have a problem that I'd like some advice/help in solving---it has to do with R's pass-by-value system. I understand the issue, but am wondering if anyone has found a working solution in dealing with it for cases when one wants to modify an object inside of a method, specifically whe