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
mailinglist.honey...@gmail.com wrote:
 Hi,

 On Fri, Nov 19, 2010 at 10:09 AM, amit jain budd...@indiatimes.com wrote:
 Hi All,

 Can anyone point to any package/resouce to schedule a job in R which runs a 
 .R file at a specified time ?

 I couldn't find anything useful in R Reference manual or RSiteSearch. I am 
 sure its there but i am unable to locate.

 If you're on a *nix-type machine, look into cron:
 http://en.wikipedia.org/wiki/Cron

 --
 Steve Lianoglou
 Graduate Student: Computational Systems Biology
  | Memorial Sloan-Kettering Cancer Center
  | Weill Medical College of Cornell University
 Contact Info: http://cbio.mskcc.org/~lianos/contact

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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, col1, is a vector of numeric, and each
element of a vector must have the same data type (numeric, factor,
etc), it will coerce the data coming in to have the same data type (if
it can).  In this case, the data type is numeric.  Had it been a
character coming in, because it can't coerce a character to a numeric,
it would have made the entire vector a vector of characters:

 test3[2,1] - 'b'
 test3$col1
[1] 1 b 3

Hope that demonstrates what's probably going on,

Jeff.

On Fri, Nov 5, 2010 at 3:54 PM, Wade Wall wade.w...@gmail.com wrote:
 Hi all,

 I have a dataframe (df1) that I am trying to select values from to a second
 dataframe that at the current time is only for the selected items from df1
 (df2).  The values that I am trying to save from df1 are factors with
 alphanumeric names

 df1 looks like this:

 'data.frame':   3014 obs. of  13 variables:
  $ Num         : int  1 1 1 2 2 2 3 3 3 4 ...
  $ Tag_Num     : int  1195 1195 1195 1162 1162 1162 1106 1106 1106 1173 ...
  $ Site        : Factor w/ 25 levels PYBR002A,PYBR003B,..: 1 1 1 1 1 1 1
 1 1 1 ...
  $ Site_IndNum : Factor w/ 1044 levels PYBR002A_001,..: 1 1 1 2 2 2 3 3 3
 4 ...
   ...
  $ Area        : num  463.3 29.5 101.8 152.9 34.6 ...

 However, whenever I try to assign values, like this

 df2[j,1]-df2$Site[i]

 the values are changed from alphanumeric (e.g. PYBR003A) to numerals (e.g.
 1).

 Does anyone know why this is happening and how I can assign the actual
 values from df1 to df2?

 Thanks in advance,

 Wade

        [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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

2010-11-05 Thread Jeffrey Spies
Glad you figured it out, but just be aware that if you set one value
of the column to be a character, it will make the whole vector
characters.  This could cause issues for analysis if you need numerics
or factors.  If the column is supposed to be a factor to begin with,
set it to be so; if you have two data frames, one with a column of
factors (dat2) and one with what should be a column of factors (dat1),
you can use something like this:

dat1$columnThatShouldBeFactors - as.factor(
dat1$columnThatShouldBeFactors,
levels=levels(dat2$columnThatIsAlreadyFactors)
)

Cheers,

Jeff.

On Fri, Nov 5, 2010 at 6:03 PM, Wade Wall wade.w...@gmail.com wrote:
 Hi all,

 Thanks for the help.  Jeffrey was right; my initial dataframe did not have
 the columns defined for factors.  I solved it using Jorge's example of using
 as.character.

 Sorry for not being more clear before.

 Wade

 On Fri, Nov 5, 2010 at 4:12 PM, Jeffrey Spies jsp...@virginia.edu wrote:

 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, col1, is a vector of numeric, and each
 element of a vector must have the same data type (numeric, factor,
 etc), it will coerce the data coming in to have the same data type (if
 it can).  In this case, the data type is numeric.  Had it been a
 character coming in, because it can't coerce a character to a numeric,
 it would have made the entire vector a vector of characters:

  test3[2,1] - 'b'
  test3$col1
 [1] 1 b 3

 Hope that demonstrates what's probably going on,

 Jeff.

 On Fri, Nov 5, 2010 at 3:54 PM, Wade Wall wade.w...@gmail.com wrote:
  Hi all,
 
  I have a dataframe (df1) that I am trying to select values from to a
  second
  dataframe that at the current time is only for the selected items from
  df1
  (df2).  The values that I am trying to save from df1 are factors with
  alphanumeric names
 
  df1 looks like this:
 
  'data.frame':   3014 obs. of  13 variables:
   $ Num         : int  1 1 1 2 2 2 3 3 3 4 ...
   $ Tag_Num     : int  1195 1195 1195 1162 1162 1162 1106 1106 1106 1173
  ...
   $ Site        : Factor w/ 25 levels PYBR002A,PYBR003B,..: 1 1 1 1 1
  1 1
  1 1 1 ...
   $ Site_IndNum : Factor w/ 1044 levels PYBR002A_001,..: 1 1 1 2 2 2 3
  3 3
  4 ...
    ...
   $ Area        : num  463.3 29.5 101.8 152.9 34.6 ...
 
  However, whenever I try to assign values, like this
 
  df2[j,1]-df2$Site[i]
 
  the values are changed from alphanumeric (e.g. PYBR003A) to numerals
  (e.g.
  1).
 
  Does anyone know why this is happening and how I can assign the actual
  values from df1 to df2?
 
  Thanks in advance,
 
  Wade
 
         [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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,
sachinthaka.abeyward...@allianz.com.au wrote:

 Hi all,

 Just following on from a previous thread (for loop). Is there a parallel
 'for' loop like matlab (parfor maybe?). I know there was a Nvidia GPU
 version for blas somewhere. But is there a CPU or a GPU version of the for
 loop?

 Thanks,
 Sachin
 p.s. sorry about the corporate notice below: cant get rid of it. Don't have
 other mail client access at the office :(

 --- Please consider the environment before printing this email ---

 Allianz - Best General Insurance Company of the Year 2010*
 Allianz - General Insurance Company of the Year 2009+

 * Australian Banking and Finance Insurance Awards
 + Australia and New Zealand Insurance Industry Awards

 This email and any attachments has been sent by Allianz Australia Insurance 
 Limited (ABN 15 000 122 850) and is intended solely for the addressee. It is 
 confidential, may contain personal information and may be subject to legal 
 professional privilege. Unauthorised use is strictly prohibited and may be 
 unlawful. If you have received this by mistake, confidentiality and any legal 
 privilege are not waived or lost and we ask that you contact the sender and 
 delete and destroy this and any other copies. In relation to any legal use 
 you may make of the contents of this email, you must ensure that you comply 
 with the Privacy Act (Cth) 1988 and you should note that the contents may be 
 subject to copyright and therefore may not be reproduced, communicated or 
 adapted without the express consent of the owner of the copyright.
 Allianz will not be liable in connection with any data corruption, 
 interruption, delay, computer virus or unauthorised access or amendment to 
 the contents of this email. If this email is a commercial electronic message 
 and you would prefer not to receive further commercial electronic messages 
 from Allianz, please forward a copy of this email to 
 unsubscr...@allianz.com.au with the word unsubscribe in the subject header.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] ggplot2: how to label lines?

2010-10-26 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(time, measure, data=dat, colour=subject, geom=line)
p

What would be the preferred way to add a single label to every line?
For instance, labels might be most readable at the beginning, end, or
peak (max value) of every line.  I could do:

p + geom_text(aes(label=subject))

But this gets messy when the labels are longer than single digits;
instead, I want a single label per line. I suppose a dataset could be
put together composed of single points and labels and then layered
atop p, but perhaps there is a more direct method.

Any help would be greatly appreciated,

Jeff.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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 insertion
into whatever report tool they use.  Note that the latter will require
a change to the preamble to not constantly be in math mode.

Mac: http://www.chachatelier.fr/programmation/latexit_en.php
Windows: http://www.thrysoee.dk/laeqed/

Hope that helps,

Jeff.

On Mon, Oct 25, 2010 at 12:59 AM, Johannes Huesing
johan...@huesing.name wrote:
 I am about to give an introduction to R to some clinical data managers
 used to SAS. There is already a lot of material in printed form and
 on the web that paves the way. What I haven't found so far are text
 wrapping capabilities in setting tables in raw text as in SAS PROC
 REPORT.

 At the moment i would direct them at producing HTML output from R
 and pipe the result through lynx. Coming from SAS they may not be
 prepared to walk the Unix way of choosing the best tool for the
 right job. Have I overlooked a package that does something similar
 to SAS PROC REPORT?
 --
 Johannes Hüsing               There is something fascinating about science.
                              One gets such wholesale returns of conjecture
 mailto:johan...@huesing.name  from such a trifling investment of fact.
 http://derwisch.wikidot.com         (Mark Twain, Life on the Mississippi)

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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 by tabs, which I think, by looking at your other
code, is what you get.

sapply(dat, function(x){
tmp-unlist(strsplit(x, '\t', fixed=T))
out - list(tmp[seq_along(tmp)[-1]])
names(out) - tmp[1]
out
}, USE.NAMES=F)

The one difference between the two is that if you have a COG with no
pathways (might not be realistic or that big of a deal), this solution
will have the COG name in the list with a value of character(0) where
Gabor's will omit the COG completely. Again, probably not a big deal.

Cheers,

Jeff.

On Sun, Oct 10, 2010 at 11:40 AM, Alison Waller alison.wal...@embl.de wrote:
 Hi all,

 I have a large table mapping thousands of COGs(groups of genes) to pathways.
 # Ex
 COG0001 patha   pathb   pathc
 COG0002 pathd   pathe
 COG0003 pathe   pathf   pathg   pathh
 ##

 I would like to combine this information into a big list such as below
 COG2PATHWAY-list(COG0001=c(patha,pathb,pathc),COG0002=c(pathd,pathe),COG0003=c(pathf,pathg,pathh))

 I am stuck and have tried various methods involving (probably mangled)
 versions of lappy and loops.

 Any suggestions on the most efficient way to do this would be great.

 Thanks,

 Alison

 Here is my latest attempt.

 #

 line_num-length(scan(file=/g/bork8/waller/test_COGtoPath.txt,what=character,sep=\n))
 COG2Path-vector(list,line_num)
 COG2Path-lapply(1:(line_num-1),function(x)
 scan(file=/g/bork8/waller/test_COGtopath.txt,skip=x,nlines=1,quiet=T,what='character',sep=\t))

 #

 I am getting an error

 #

COG2Path-lapply(1:(line_num-1),function(x)
 scan(file=/g/bork8/waller/test_COGtopath.txt,skip=x,nlines=1,quiet=T,what='character',sep=\t))
 Error in file(file, r) : cannot open the connection
 In addition: Warning message:
 In file(file, r) :

 But if I do scan alone I don't get an error

 # then I suppose it looks like the easiest wasy to name the list variables
 is using unix to cut the first column out and then read that in.
 names(COG2Path)-scan(file=/g/bork8/waller/test_col_names.txt,sep=\t,what=character)

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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-Institutional Plan-Daily
Dividend Option;1001.;1001.;1001.;02-Oct-2010,106511;AIG
India Liquid Fund-Institutional Plan-Growth
Option;1210.4612;1210.4612;1210.4612;02-Oct-2010)

Then you can use this to get a data frame:

as.data.frame(do.call(rbind, lapply(MF_Data, function(x)
unlist(strsplit(x, ';')

Cheers,

Jeff.

On Sat, Oct 9, 2010 at 12:30 PM, jim holtman jholt...@gmail.com wrote:
 Is this what you are after:

 x - c(Scheme Code;Scheme Name;Net Asset Value;Repurchase Price;Sale 
 Price;Date
 + , 
 +  ,Open Ended Schemes ( Liquid )
 + , 
 + , 
 + , AIG Global Investment Group Mutual Fund
 + , 106506;AIG India Liquid Fund-Institutional Plan-Daily Dividend
 Option;1001.;1001.;1001.;02-Oct-2010
 + , 106511;AIG India Liquid Fund-Institutional Plan-Growth
 Option;1210.4612;1210.4612;1210.4612;02-Oct-2010
 + , 106507;AIG India Liquid Fund-Institutional Plan-Weekly Dividend
 Option;1001.8765;1001.8765;1001.8765;02-Oct-2010
 + , 106503;AIG India Liquid Fund-Retail Plan-DailyDividend
 Option;1001.;1001.;1001.;02-Oct-2010)

 myData - read.table(textConnection(x[7:10]), sep=';')
 closeAllConnections()
 str(myData)
 'data.frame':   4 obs. of  6 variables:
  $ V1: int  106506 106511 106507 106503
  $ V2: Factor w/ 4 levels AIG India Liquid Fund-Institutional
 Plan-Daily Dividend Option,..: 1 2 3 4
  $ V3: num  1001 1210 1002 1001
  $ V4: num  1001 1210 1002 1001
  $ V5: num  1001 1210 1002 1001
  $ V6: Factor w/ 1 level 02-Oct-2010: 1 1 1 1
 myData
      V1
 V2       V3       V4       V5          V6
 1 106506  AIG India Liquid Fund-Institutional Plan-Daily Dividend
 Option 1001.000 1001.000 1001.000 02-Oct-2010
 2 106511          AIG India Liquid Fund-Institutional Plan-Growth
 Option 1210.461 1210.461 1210.461 02-Oct-2010
 3 106507 AIG India Liquid Fund-Institutional Plan-Weekly Dividend
 Option 1001.876 1001.876 1001.876 02-Oct-2010
 4 106503          AIG India Liquid Fund-Retail Plan-DailyDividend
 Option 1001.000 1001.000 1001.000 02-Oct-2010




 On Sat, Oct 9, 2010 at 12:18 PM, Santosh Srinivas
 santosh.srini...@gmail.com wrote:
 Newbie question ...

 I am looking something equivalent to read.delim but  which accepts a text 
 line as parameter instead of a file input.

 Below is my problem, I'm unable to get the exact output which is a simple 
 data frame of the data where the delimiter exists ... coming quite close 
 though

 I have a data frame with 10 lines called MF_Data
 MF_Data [1:10]
  [1] Scheme Code;Scheme Name;Net Asset Value;Repurchase Price;Sale 
 Price;Date
  [2] 
  [3] Open Ended Schemes ( Liquid )
  [4] 
  [5] 
  [6] AIG Global Investment Group Mutual Fund
  [7] 106506;AIG India Liquid Fund-Institutional Plan-Daily Dividend 
 Option;1001.;1001.;1001.;02-Oct-2010
  [8] 106511;AIG India Liquid Fund-Institutional Plan-Growth 
 Option;1210.4612;1210.4612;1210.4612;02-Oct-2010
  [9] 106507;AIG India Liquid Fund-Institutional Plan-Weekly Dividend 
 Option;1001.8765;1001.8765;1001.8765;02-Oct-2010
 [10] 106503;AIG India Liquid Fund-Retail Plan-DailyDividend 
 Option;1001.;1001.;1001.;02-Oct-2010


 Now for the lines below .. they are delimted by ; ... I am using

  tempTxt - MF_Data[7]
  MF_Data_F -   unlist(strsplit(tempTxt,;, fixed = TRUE))
  tempTxt - MF_Data[8]
  MF_Data_F1 -  unlist(strsplit(tempTxt,;, fixed = TRUE))
  MF_Data_F - rbind(MF_Data_F,MF_Data_F1)

 But MF_Data_F is not a simple 2X6 data frame which is what I want

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




 --
 Jim Holtman
 Cincinnati, OH
 +1 513 646 9390

 What is the problem that you are trying to solve?

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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 ehl...@ucalgary.ca wrote:
 On 2010-10-07 10:10, Jim Silverton wrote:

 Hello,
 I gave  a list of 2 x 2 matrices called matlist. I have about 5000 2 x 2
 matrices. I would like to count how many of each 2 x 2 unique matrix I
 have.
 So I am thinking that I need a list of the unique 2 x 2 matrices and their
 counts. Can anyone help.


 Here's one way, using the plyr package:

  require(plyr)
  ## make a list of 2X2 matrices
  L - vector('list', 5000)
  set.seed(4321)
  for(i in 1:5000) L[[i]] - matrix(round(runif(4), 1), 2, 2)

  ## convert each matrix to a string of 4 numbers, then
  ## form dataframe
  dL - ldply(L, function(.x) toString(unlist(.x)))

  ## add an index vector
  dL$ind - seq_len(5000)

  ## count unique strings; return string, frequency, indeces
  result - ddply(dL, .(V1), summarize,
                              freq=length(V1),
                              idx=toString(ind))


   -Peter Ehlers

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] StrSplit

2010-10-09 Thread Jeffrey Spies
Obviously Jim's solution does work, and I did not intend to imply it
didn't.  In fact, his read.table solution would work both if the OP
had a semi-colon delimited file to begin with (which I was trying to
say was ideal from a workflow standpoint) or a vector of strings (for
use when paired with textConnections).  Using strsplit is merely
another solution for the latter situation.  I thought the OP might
appreciate seeing how to use the function that they indicated they
were having problems with.  Plus, I have a penchant for R-ishly
unreadble code. ;)

Thanks for clarifying,

Jeff.

On Sat, Oct 9, 2010 at 1:04 PM, David Winsemius dwinsem...@comcast.net 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 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-Institutional Plan-Daily
 Dividend Option;1001.;1001.;1001.;02-Oct-2010,106511;AIG
 India Liquid Fund-Institutional Plan-Growth
 Option;1210.4612;1210.4612;1210.4612;02-Oct-2010)

 Then you can use this to get a data frame:

 as.data.frame(do.call(rbind, lapply(MF_Data, function(x)
 unlist(strsplit(x, ';')


 If you are suggesting that Jim's solution would not work here, then I would
 disagree and suggest you try offering your vector (without the cr's
 inserted by our mail clients) to his code. It should work just fine and be
 far more readable.

 On the other hand if you were offering this with an explanation that
 strsplit's split argument is more flexible than the sep argument in the read
 functions because it accepts regular expressions and so can handle
 situations where multiple separators exist in the same line, then I would
 applaud you.

 --
 David.

 Cheers,

 Jeff.

 On Sat, Oct 9, 2010 at 12:30 PM, jim holtman jholt...@gmail.com wrote:

 Is this what you are after:

 x - c(Scheme Code;Scheme Name;Net Asset Value;Repurchase Price;Sale
 Price;Date

 + , 
 +  ,Open Ended Schemes ( Liquid )
 + , 
 + , 
 + , AIG Global Investment Group Mutual Fund
 + , 106506;AIG India Liquid Fund-Institutional Plan-Daily Dividend
 Option;1001.;1001.;1001.;02-Oct-2010
 + , 106511;AIG India Liquid Fund-Institutional Plan-Growth
 Option;1210.4612;1210.4612;1210.4612;02-Oct-2010
 + , 106507;AIG India Liquid Fund-Institutional Plan-Weekly Dividend
 Option;1001.8765;1001.8765;1001.8765;02-Oct-2010
 + , 106503;AIG India Liquid Fund-Retail Plan-DailyDividend
 Option;1001.;1001.;1001.;02-Oct-2010)

 myData - read.table(textConnection(x[7:10]), sep=';')
 closeAllConnections()
 str(myData)

 'data.frame':   4 obs. of  6 variables:
  $ V1: int  106506 106511 106507 106503
  $ V2: Factor w/ 4 levels AIG India Liquid Fund-Institutional
 Plan-Daily Dividend Option,..: 1 2 3 4
  $ V3: num  1001 1210 1002 1001
  $ V4: num  1001 1210 1002 1001
  $ V5: num  1001 1210 1002 1001
  $ V6: Factor w/ 1 level 02-Oct-2010: 1 1 1 1

 myData

     V1
 V2       V3       V4       V5          V6
 1 106506  AIG India Liquid Fund-Institutional Plan-Daily Dividend
 Option 1001.000 1001.000 1001.000 02-Oct-2010
 2 106511          AIG India Liquid Fund-Institutional Plan-Growth
 Option 1210.461 1210.461 1210.461 02-Oct-2010
 3 106507 AIG India Liquid Fund-Institutional Plan-Weekly Dividend
 Option 1001.876 1001.876 1001.876 02-Oct-2010
 4 106503          AIG India Liquid Fund-Retail Plan-DailyDividend
 Option 1001.000 1001.000 1001.000 02-Oct-2010




 On Sat, Oct 9, 2010 at 12:18 PM, Santosh Srinivas
 santosh.srini...@gmail.com wrote:

 Newbie question ...

 I am looking something equivalent to read.delim but  which accepts a
 text line as parameter instead of a file input.

 Below is my problem, I'm unable to get the exact output which is a
 simple data frame of the data where the delimiter exists ... coming quite
 close though

 I have a data frame with 10 lines called MF_Data

 MF_Data [1:10]

  [1] Scheme Code;Scheme Name;Net Asset Value;Repurchase Price;Sale
 Price;Date
  [2] 
  [3] Open Ended Schemes ( Liquid )
  [4] 
  [5] 
  [6] AIG Global Investment Group Mutual Fund
  [7] 106506;AIG India Liquid Fund-Institutional Plan-Daily Dividend
 Option;1001.;1001.;1001.;02-Oct-2010
  [8] 106511;AIG India Liquid Fund-Institutional Plan-Growth
 Option;1210.4612;1210.4612;1210.4612;02-Oct-2010
  [9] 106507;AIG India Liquid Fund-Institutional Plan-Weekly Dividend
 Option;1001.8765;1001.8765;1001.8765;02-Oct-2010
 [10] 106503;AIG India Liquid Fund-Retail Plan-DailyDividend
 Option;1001.;1001.;1001.;02-Oct-2010


 Now for the lines below .. they are delimted by ; ... I am using

  tempTxt - MF_Data[7]
  MF_Data_F -   unlist(strsplit(tempTxt,;, fixed = TRUE))
  tempTxt - MF_Data[8]
  MF_Data_F1 -  unlist(strsplit(tempTxt,;, fixed = TRUE))
  MF_Data_F - rbind(MF_Data_F,MF_Data_F1)

 But MF_Data_F

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)/sum(temp)
})

For mat[2,4], I get 0 (as did the other solutions), and you get 1, so
check on that. If you want the divide-by-0 NaNs to be 0, you can check
that by replacing

min(temp)/sum(temp)

with:

ifelse(is.nan(val-min(temp)/sum(temp)), 0, val)

This has an advantage over:

mat[is.na(mat)] - 0

in that you might have true missingness in your data and is.na won't
be able to distinguish it.

Cheers,

Jeff.

On Fri, Oct 8, 2010 at 1:19 AM, burgundy saub...@yahoo.com wrote:

 Hello,

 I have a dataframe (tab separated file) which looks like the example below -
 two values separated by a comma, and tab separation between each of these.

     [,1]  [,2]  [,3]  [ ,4]
 [1,] 0,1  1,3   40,10  0,0
 [2,] 20,5  4,2  10,40  10,0
 [3,] 0,11  1,2  120,10  0,0

 I would like to calculate the percentage of the smallest number separated by
 the comma by:
 1) summing the values e.g. for [1,3] where 40,10, 40+10 = 50
 2) taking the first value and dividing it by the total e.g. for [1,3], 40/50
 = 0.8
 3) where the value generated by 2) is 0.5, print 1-value, otherwise, leave
 value e.g. for [1,3], where value is 0.8, print 1-0.8 = 0.2

 plan to generate file like:

    [,1]  [,2]  [,3]  [,4]
 [1,] 1   0.25  0.2  0
 [2,] 0.2  0.33  0.2  1
 [3,] 1  0.33  0.08  0

 Apologies, I know this is very complex. Any help, even just some pointers on
 how to write a general function where values are separated by a comma, is
 realy very much appreciated!

 Thank you

 --
 View this message in context: 
 http://r.789695.n4.nabble.com/function-using-values-separated-by-a-comma-tp2967870p2967870.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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 ralf.bie...@gmail.com wrote:
 Can one create a variable through a function by name

 createVariable - function(name) {
        outputVariable = name
        name - NULL
 }

 after calling

 createVariable(myVar)

 I would like to have a variable myVar initialized with NULL in my
 environment. Is this possible?

 Ralf

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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 hubd...@gmail.com wrote:
 Does anyone know why a data frame created with empty character columns
 converts them to integer columns?

 df-data.frame(a=character(0),b=character(0))
 df-rbind(df,c(a,a))
 typeof(df[1,1])
 [1] integer

 AsIs doesn't help:

 df-data.frame(a=I(character(0)),b=I(character(0)))
 df-rbind(df,I(c(a,a)))
 typeof(df[1,1])
 [1] integer

 Any suggestions on how to overcome this would be appreciated.

 Best wishes,

 David

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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 naturally accomplished using vector operations on tabular
data, where columns represent variables of the same data type and rows
represent observations of these variables for a given member of the
dataset.  Fortunately, these are core components of R.  For instance,
we can easily perform complex selections of variables and/or members,
which, more often than not, serve as input to or power the functions
that generate the statistics and graphics we care about.
Unfortunately, vector operations seem to be difficult for people to
learn how to use properly, and there are penalties for not using them,
but as they say: no pain, no gain. :)

If you'd be willing to share the materials you create for your talk,
I'd be interested in seeing them.

Cheers,

Jeff.

On Wed, Oct 6, 2010 at 5:05 PM, Michael Friendly frien...@yorku.ca wrote:
  I'm giving a talk about some aspects of language and conceptual tools for
 thinking about how
 to solve problems in several programming languages for statistical computing
 and graphics. I'm particularly
 interested in language features that relate to:

 o expressive power: ease of translating what you want to do into the results
 you want
 o elegance: how well does the code provide a simple human-readable
 description of what is done?
 o extensibility: ease of generalizing a method to wider scope
 o learnability: your learning curve (rate, asymptote)

 For R, some things to cite are (a) data and function objects, (b)
 object-oriented methods (S3  S4); (c) function mapping over data with
 *apply methods and plyr.

 What other language features of R should be on this list?  I would welcome
 suggestions (and brief illustrative examples).

 -Michael


 --
 Michael Friendly     Email: friendly AT yorku DOT ca
 Professor, Psychology Dept.
 York University      Voice: 416 736-5115 x66249 Fax: 416 736-5814
 4700 Keele Street    Web:   http://www.datavis.ca
 Toronto, ONT  M3J 1P3 CANADA

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R-help

2010-10-05 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,

Jeff.

On Tue, Oct 5, 2010 at 2:30 AM, Joshua Wiley jwiley.ps...@gmail.com wrote:
 On Mon, Oct 4, 2010 at 9:13 PM, Lemarian WallaceIII tott...@yahoo.com wrote:
 Im trying to simulate the rolling of a pair of dice

 this is my function:
 #function to simulate tosses of a pair of dice
 #from the simulation, the program returns the empirical probability of
 #observing a double
 count - 0
 for(j in 1:sim){#begin loop
 die1 - sample(1:6,1)
 print(die1)
 die2 - sample(1:6,1)
 print(die2)
 count - ifelse(die1 == die2, count + 1, count)
 }#end loop
 emprob - count/sim
 return(count,emprob)
 } #end program


 these are the errors that keep coming up:
 Error in 1:sim : 'sim' is missing

 You need to define an object called 'sim', otherwise you are telling R
 to go look up the value of a non-existent variable.  Does your
 function have a first part?  All I am seeing is the body and the end.

 Josh



 How do I correct this?



        [[alternative HTML version deleted]]


 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



 --
 Joshua Wiley
 Ph.D. Student, Health Psychology
 University of California, Los Angeles
 http://www.joshuawiley.com/

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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
jumlong.u...@gmail.com wrote:
 Dear all.
 I have data with 2 variable x,y size 1.
 I want to sampling from this data with size 100.
 How I can do it.
 THANK.

 --
 Jumlong Vongprasert
 Institute of Research and Development
 Ubon Ratchathani Rajabhat University
 Ubon Ratchathani
 THAILAND
 34000

        [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Sampling from data set

2010-10-05 Thread Jeffrey Spies
If poproh.3 was your dataset as a data.frame (an object with row and
column dimensions), you need a comma following the row selection
(sample(...)) to indicate that you want to select those rows and all
columns:

newsample -poprho.3[sample(1:1,100),] # note the last comma in the brackets

General use is:

my.data.frame[rows,columns]

Where either rows or columns (or both) can be left blank to indicate
that you want all of them.  Similarly, a selection of the first column
would have been (comma followed by column number):

newsample -poprho.3[sample(1:1,100),1]

That's why your:

newsample -as.matrix(nameofdataset[sample(1:1,100),])

worked; the as.matrix wasn't necessary to simply sample the data.

Cheers,

Jeff.

On Tue, Oct 5, 2010 at 3:54 AM, Jumlong Vongprasert
jumlong.u...@gmail.com wrote:
 Dear Jeffrey.
 I used newsample -as.matrix(nameofdataset[sample(1:1,100),]).
 Now it include all 2 variable.
 Thank you for your answer to inspire.
 Jumlong

 2010/10/5 Jeffrey Spies jsp...@virginia.edu

 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
 jumlong.u...@gmail.com wrote:
  Dear all.
  I have data with 2 variable x,y size 1.
  I want to sampling from this data with size 100.
  How I can do it.
  THANK.
 
  --
  Jumlong Vongprasert
  Institute of Research and Development
  Ubon Ratchathani Rajabhat University
  Ubon Ratchathani
  THAILAND
  34000
 
         [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 



 --
 Jumlong Vongprasert
 Institute of Research and Development
 Ubon Ratchathani Rajabhat University
 Ubon Ratchathani
 THAILAND
 34000


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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 wenyue...@gmail.com wrote:
 Hey All,

 I am new in R.  Need help on code that can open the .tar.gz file in R under
 Windows.  Can any one help.

 Thanks in Advance.

 Wayne

        [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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 every
row--a change made in the first line:

for (i in 1:dim(ex)[1]) {
if(ex[i,3]==A|| ex[i,3]==C){
ex[i,4]- -
}else {
ex[i,4]-10
}
}

1:dim(ex)[1] is then a vector of row index values that is looped over.

A more R-ish version of this might be:

ex[,4] - ifelse(ex$eff == 'A' | ex$eff == 'C', -, 10)

I'm not sure this is the case, but if - is supposed to represent
missingness, missing values are represented by `NA`s in R.

ex[,4] - ifelse(ex$eff == 'A' | ex$eff == 'C', NA, 10)

?NA for more info.  Note: those are not single quotes, but instead back-ticks.

Hope that helps,

Jeff.

On Sun, Oct 3, 2010 at 4:58 AM, Bapst Beat beat.ba...@braunvieh.ch wrote:
  Hello list members

 I have a problem with modifying a data.frame.
 As an example given is a data.frame called ex :


 ex-data.frame(id=c(1,2,3,4,5,6),obs=c(14,9,20,36,55,47),eff=c(A,A,B,C,C,C))


 After that I would like to modify the object ex with the following short 
 script:


 for (i in ex) {

 if(ex[i,3]==A|| ex[i,3]==C){

 ex[i,4]--

 }

 else {

 ex[i,4]-10

 }

 }

 This script is creating an error message:

 Fehler in if (ex[i, 3] == A || ex[i, 3] == C) { :
  Fehlender Wert, wo TRUE/FALSE nötig ist


 Why this script  doesn't  work properly?

 Thanks a lot for your hints

 Beat

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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 笑啸 dingdongl...@126.com:
 dear professor:
 I am a doctor of urinary,and I am developing a nomogram of bladder tumor.Now 
 I have a problem about this.
 I have got the result like this through analysing the dataset exp11.sav 
 through multinominal logistic regression by SPSS 17.0.(the Sig. is high,that 
 is good ,it is just aexperimental data )

 Parameter Estimates

 Ya

 B

 Std. Error

 Wald

 df

 Sig.

 Exp(B)

 95% Confidence Interval for Exp(B)

 Lower Bound

 Upper Bound

 1

 Intercept

 -1.338

 .595

 5.059

 1

 .024







 T.Grade

 .559

 .319

 3.076

 1

 .079

 1.749

 .936

 3.265

 Sex

 .920

 .553

 2.766

 1

 .096

 2.511

 .849

 7.428

 Smoking

 -.896

 .474

 3.580

 1

 .058

 .408

 .161

 1.033

 a. The reference category is: 0.


 And after that,I want to develop the nomogram through R-Project.
 And
 I load the package rms

 T.Grade-factor(0:3,labels=c(G0, G1, G2,G3))
 Sex-factor(0:1,labels=c(F,M))
 Smoking-factor(0:1,labels=c(No,yes))
 L-0.559T.Grade-0.896Smoking+0.92Sex-1.338      # error  (错误: 
 不适用于非函数;error:it is not fit the non-function)

 The R-project index that the last program error.

 can you tell me where is the mistake.and how to get the correct equation .

 thank you for you help!
 And I an sorry about my poor english!

                                                                               
                    truly yours

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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 has extended that code for variable selection/regression:

http://userwww.service.emory.edu/~bajohn3/software.html

Maybe that's a start; if you find more by following Peter's suggestion
of privately contacting authors, please follow-up with the list.

Cheers,

Jeff.

On Sun, Oct 3, 2010 at 1:38 PM, Peter Dalgaard pda...@gmail.com wrote:
 On 10/03/2010 06:32 PM, David Winsemius wrote:


 Ahmed Albatineh wrote:


 Are you aware of any package that calculates Ranked Set Sample? If you
 have
 a code that you are willing to share, I will acknowledge that in my work.
 Thanks much

 Ahmed


 I wonder if this is a phrase that is uniformly understood? One possibility
 is that you are asking to sample elements of a set based on some ranking
 function. In that case you may need to describe in more detail how you want
 to handle ties and whether this function is supposed to deal with
 multivariate strata. (There are many base functions that handle univariate
 situations and there are packages that provide support for more complex
 ones.)

 You are also requested (in the Posting Guide) to provide an example  that
 can be cut and pasted and desired results against which responder can judge
 the degree to which their efforts agree with your hopes.


 It's a fairly well-defined concept. I.e., you can google for it...

 On the other hand, same search points to authors like Jeff Terpstra who
 explicitly says that he codes in R, so maybe ask him instead of the the
 world at large?


 --
 Peter Dalgaard
 Center for Statistics, Copenhagen Business School
 Phone: (+45)38153501
 Email: pd@cbs.dk  Priv: pda...@gmail.com

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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
ch...@trickysolutions.com.au wrote:
 Hi everyone,



 I’m trying to install reshape2.



 But when I click on “install package” it’s not coming up!?!?! I’m getting
 reshape, but no reshape2?



 I’ve also tried download.packages(reshape2, destdir=c:\\) 
 download.packages(Reshape2, destdir=c:\\)…but no luck!!!



 Does anyone have any ideas what could be going on?



 Chris Howden

 Founding Partner

 Tricky Solutions

 Tricky Solutions 4 Tricky Problems

 Evidence Based Strategic Development, IP development, Data Analysis,
 Modelling, and Training

 (mobile) 0410 689 945

 (fax / office) (+618) 8952 7878

 ch...@trickysolutions.com.au

        [[alternative HTML version deleted]]


 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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
case, you are setting data.name to be the data frame returned by
read.dta:

data.name - read.dta(file.choose())

If you'd rather, you could use:

kelleya - read.dta(file.choose())
summary(kelleya)

Hope that helps,

Jeff.

On Sat, Oct 2, 2010 at 10:01 PM, Alla Manukyan allama...@yahoo.com wrote:
 Dear Sir/Madam,
 I have just installed R for Windows. I am trying to open a stata file and I 
 have
 a problem. I have used the following commands:

 install.packages(foreign)
 library(foreign)

 data.name - read.dta(file.choose())


 # then I choose a kelleya.dta file and click on open and then I use the
 following command:

 summary(kelleya)

 Error in object[[i]] : object of type 'closure' is not subsettable
 I have also used opening an spss file using read.spss command but I get the 
 same
 error message. Can you help me please?

 Alla

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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 sochs...@bcm.edu wrote:
 Hi,

 Take a matrix with missing values:

 X = matrix(rnorm(10), ncol = 5)
 X[2,4]=NA
 X
           [,1]       [,2]       [,3]       [,4]       [,5]
 [1,] -0.1566427 -0.7382232 -1.0564624 -0.8412139  0.9370319
 [2,] -1.0289865 -0.8452054 -0.1349459         NA -0.1749113

 I want to apply a custom function over the rows such that the NAs are ignored 
 in a similar fashion as to how the following works.

 means-apply(X,1,mean,na.rm=TRUE)

 Custom function:

 liptak-function (x,df) 
 2*(pnorm(abs(sum(x*df)/sqrt(sum(df^2))),lower.tail=FALSE))

 I want to be able to do the following:

rslt-apply(X,1,liptak,na.rm=TRUE)

 Can someone point me in the right direction on how to incorporate the use of 
 na.rm into my function?


 Scott

 sessionInfo()
 R version 2.11.0 (2010-04-22)
 i386-pc-mingw32

 locale:
 [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252
 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
 [5] LC_TIME=English_United States.1252

 attached base packages:
 [1] stats     graphics  grDevices utils     datasets  methods   base

 loaded via a namespace (and not attached):
 [1] tools_2.11.0

 Scott A. Ochsner, PhD
 NURSA Bioinformatics
 Baylor College of Medicine
 One Baylor Plaza
 Mail Stop: BCM-130
 Houston, TX 77030
 Voice: (713) 798-6227
 Fax: (713) 790-1275
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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
...
out_file - paste(frames.chr, i, .meth.txt, sep=) # dynamic file name
write.table(frames, file=out_file, sep=\t, quote=F, col.names=T,
row.names=F) # use var you just made
}

Replace the ???s.

Jeff.

On Fri, Oct 1, 2010 at 11:27 AM, qcshare qcsh...@gmail.com wrote:

 It doesn't work...
 where should change?
 Thanks.
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Help-How-to-use-loop-to-achieve-this-aim-tp2819894p2922193.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[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 at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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

2008-06-19 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 when working with
S4.  I'm aware that R.oo is able to deal with this using S3, but I'd really
rather stick to S4.

The basics of what I would like to do are coded below:

setClass(MyMatrix,
representation(
parameters=matrix,
uniqueCount=numeric
),
prototype(
parameters=matrix(numeric(0),0,0),
uniqueCount=1   
)
)

setGeneric(createUniqueName, function(object)
standardGeneric(createUniqueName))

setMethod(createUniqueName, MyMatrix, function(object){
retval - paste(unique_, [EMAIL PROTECTED], sep=)
[EMAIL PROTECTED] - [EMAIL PROTECTED] + 1
return(retval)
})

x - new(MyMatrix, parameters=matrix(0, 2, 2))
createUniqueName(x) # returns unique_1
x # [EMAIL PROTECTED] is still 1

I understand why this is happening, but am wondering how people in the
community have dealt with it, specifically when using S4.  Any advice would
be appreciated.  Also, I am aware that this is somewhat of a silly example,
but it should allow you to see what I'm trying to accomplish.

Thank you,

Jeff.


-- 
View this message in context: 
http://www.nabble.com/S4-pass-by-value-work-around--tp17997553p17997553.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


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

2008-06-19 Thread Jeffrey Spies

Thanks for the response, Martin.  While the solutions offered update the
object appropriately, we wouldn't get the desired return value (a string
followed by the counter, unique_1) when the methods are called.  Do you
know a way of dealing with this?

Jeff.


Martin Morgan wrote:
 
 Hi Jeff --
 
 two different scenarios are to overwrite the current object, along the
 lines of
 
 y - uniquify(y)
 
 where uniquify is a method like createUniqueName but returns the
 (modified) instance rather than unique name
 
 setMethod('uniquify', 'MyMatrix', function(x) {
 [EMAIL PROTECTED] - # something unique
 x
 })
 
 The second is a replacement method, along the lines of
 
 setGeneric(uniqueCount-,
 function(x, ..., value) standardGeneric(uniqueCount-))
 
 setReplaceMethod(uniqueCount,
 signature=c(x=MyMatrix, value=numeric),
 function(x, ..., value) {
 [EMAIL PROTECTED] - value
 x
 })
 
 uniqueCount(x) - uniqueCount(x) + 1
 x # now modified
 
 This is untested psuedo-code, so I hope it's right enough to get you
 going.
 
 Martin
 
 Jeffrey Spies [EMAIL PROTECTED] writes:
 
 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 when working
 with
 S4.  I'm aware that R.oo is able to deal with this using S3, but I'd
 really
 rather stick to S4.

 The basics of what I would like to do are coded below:

 setClass(MyMatrix,
  representation(
  parameters=matrix,
  uniqueCount=numeric
  ),
  prototype(
  parameters=matrix(numeric(0),0,0),
  uniqueCount=1   
  )
 )

 setGeneric(createUniqueName, function(object)
 standardGeneric(createUniqueName))

 setMethod(createUniqueName, MyMatrix, function(object){
  retval - paste(unique_, [EMAIL PROTECTED], sep=)
  [EMAIL PROTECTED] - [EMAIL PROTECTED] + 1
  return(retval)
 })

 x - new(MyMatrix, parameters=matrix(0, 2, 2))
 createUniqueName(x) # returns unique_1
 x # [EMAIL PROTECTED] is still 1

 I understand why this is happening, but am wondering how people in the
 community have dealt with it, specifically when using S4.  Any advice
 would
 be appreciated.  Also, I am aware that this is somewhat of a silly
 example,
 but it should allow you to see what I'm trying to accomplish.

 Thank you,

 Jeff.

 

-- 
View this message in context: 
http://www.nabble.com/S4-pass-by-value-work-around--tp17997553p18012246.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.