Re: [R] Efficient way of creating a shifted (lagged) variable?

2011-08-04 Thread R. Michael Weylandt
If you start looking at the time series classes (xts, zoo, etc) they have very quick and flexible lag functions built in. Might this be a slightly more efficient solution for the homebrew implementation? OurLag - function(y, k=1) { t = y[,1,drop=F]; d = y[,-1,drop=F]; if (is.matrix(y))

Re: [R] special recursive filter

2011-08-04 Thread R. Michael Weylandt
] - -1 } result - -result[-(1:wait)] In the end I'm happy with your solution! Thank you for your help! Thomas Original-Nachricht Datum: Fri, 29 Jul 2011 12:25:10 -0400 Von: R. Michael Weylandt michael.weyla...@gmail.com michael.weyla...@gmail.com An: Konrad Schubert

Re: [R] identifying weeks (dates) that certain days (dates) fall into

2011-08-04 Thread R. Michael Weylandt
You are getting 105 because the default behavior of findInterval is such that v[N+1] := + Inf (as noted in ? findInterval); that is, the last interval is actually taken to stretch from the final element of sbwl.dates unto eternity. It shouldn't be hard to write a catch line to set that to

Re: [R] Efficient way of creating a shifted (lagged) variable?

2011-08-04 Thread R. Michael Weylandt
But quite a few thousand dollars cheaper - seems a fair trade to me! Seriously though: your last few requests have been focused on time objects, so I strongly suggest you take a look at xts/zoo ( http://cran.r-project.org/web/packages/xts/index.html) -- it will make time objects much easier for

Re: [R] General indexing in multidimensional arrays

2011-08-04 Thread R. Michael Weylandt
))] } ##value integer index matrix which can be used to index datacube ind.matrix } On 08/04/2011 12:12 AM, R. Michael Weylandt michael.weyla...@gmail.com wrote: This might be a little late: but how about this (slightly clumsy) function: putValues- function(Insert, Destination

Re: [R] How to see the previous commands after save workspace/load workspace ?

2011-08-04 Thread R. Michael Weylandt
Check out ?savehistory in utils. Also, I think most GUI's do this - I can certainly attest that RStudio does Michael Weylandt On Thu, Aug 4, 2011 at 11:55 AM, Bogdan Lataianu bodins...@gmail.comwrote: I did save workspace and when I load it, I can see the variables, using ls(). But I cannot

Re: [R] functions on rows or columns of two (or more) arrays

2011-08-04 Thread R. Michael Weylandt
I hope someone experience with plyr package comes and helps because this sounds like what it does well, but for your specific example something like this works: A = rbind(a,a2) q = apply(A,2,function(x) {lm(x[1:nrow(a)] ~ x[-(1:nrow(a))])}) but yeah, that's pretty rough so I hope someone can

Re: [R] matrix rows to single numeric element

2011-08-04 Thread R. Michael Weylandt
This seems to work: apply(mat1,1,function(x){paste(x,collapse=)}) The collapse command inside of paste is (I think) the easiest way to combine strings. Michael Weylandt On Thu, Aug 4, 2011 at 5:45 PM, Wegan, Michael (DNRE) weg...@michigan.gov wrote: I have a matrix of 5 columns and

Re: [R] General indexing in multidimensional arrays

2011-08-04 Thread R. Michael Weylandt
monster! Jannis On 08/04/2011 09:58 PM, R. Michael Weylandt wrote: Hi Jannis, Like Gene, I'm not entirely sure what your code is intended to do, but it wasn't hard to adapt mine to at least print out the desired slice through the higher-dimensional array: cubeValues- function(Insert

Re: [R] Efficient way of creating a shifted (lagged) variable?

2011-08-04 Thread R. Michael Weylandt
Yes, the stats package has a lag function, but it's not really appropriate for the sample data Dimitri gave us: to wit, it's not of ts (time series) class so lag doesn't know what to do with it and gives an error message. Perhaps it's just that I never really took the time to get used to it, but

Re: [R] Which is more efficient?

2011-08-04 Thread R. Michael Weylandt
You can study this yourself using the System.time() utility: just write System.time() around any block of code and R will time it for you. Offhand, I'd guess example2 may be ever so slightly quicker since it doesn't have to create colA and colB, but not to a degree that would be noticeable for

Re: [R] R compare cells in one matrix

2011-08-05 Thread R. Michael Weylandt
*Is there a function or a package that can be used for comparation?* Given that there is no such thing as comparation, I can only guess that there's not... Michael PS -- Write back and actually explain what you are trying to do and we'll talk. On Fri, Aug 5, 2011 at 6:11 AM, kokavolchkov

Re: [R] R compare cells in one matrix

2011-08-05 Thread R. Michael Weylandt
AM, jim holtman jholt...@gmail.com wrote: But there is: Com`pa`ra´tion n. 1. A making ready; provision. Webster's Revised Unabridged Dictionary, published 1913 by C. G. Merriam Co. On Fri, Aug 5, 2011 at 9:12 AM, R. Michael Weylandt michael.weyla...@gmail.com wrote

Re: [R] Loop: noob question

2011-08-05 Thread R. Michael Weylandt
This is a textbook of when NOT to use a loop in R: rather make a function that does what you want and use the replicate function to do it repeatedly. f - function(){ return(-1000*quantile(rnorm(250,0,0.2),0.95) } x = replicate(1e5,f()) There are your desired numbers. Some general coding

Re: [R] [?]apply functions or for loop

2011-08-05 Thread R. Michael Weylandt
You should have been able to discern from the help pages that the generic apply will do it. E.g., apply(x,1,rank) Now, you'll probably want to transpose the output of apply: it's a R quirk/feature/bug/idiosyncrasy that apply(x,1,FUN) transposes the output and most of the time I wind up

Re: [R] a question on list manipulation

2011-08-05 Thread R. Michael Weylandt
There are a few moving pieces to do this: 1) the toupper and tolower functions. These can do almost everything you need: x = lapply(x,toupper) ## This changes the things inside x but won't change the names 2) Now, there are two ways to think about getting the elements from one list to another:

Re: [R] Loop: noob question

2011-08-05 Thread R. Michael Weylandt
efficient than apply() ). As here (I think), one often cannot vectorize and must loop in interpreted code, and for this replicate() is fine and yields nice clean code. But it's still a loop. Cheers, Bert On Fri, Aug 5, 2011 at 9:15 AM, R. Michael Weylandt michael.weyla...@gmail.com wrote

Re: [R] exclude matrix from matrix

2011-08-06 Thread R. Michael Weylandt
If you know the names will always work (i.e., names of y are always names of x and the rows always have names) this should do it: x[!(rownames(x) %in% rownames(y)),] I.e., those rows of x such that their names are NOT included in the row names of y. Hope this helps, Michael Weylandt On Sat,

Re: [R] Display a DataFrame in a data grid

2011-08-08 Thread R. Michael Weylandt
Welcome to the dark-side! I think the View() command will do what you want. This brings up a new window that displays the data spreadsheet style and you can scroll wherever you wish. If you want to do work in your command window, the head() and tail() commands will be of help to you. If you are

Re: [R] confidence interval as shaded band (lme)

2011-08-08 Thread R. Michael Weylandt
I don't know lme models very well, but if you have standard errors for your values, this shouldn't be too hard (as a last resort) using polygon() For example x = 1:10 y = x^2 y.Err = 2*x y.Up = y + y.Err; y.Dn =y-y.Err # This graph is actually quite ugly so don't copy the formatting

Re: [R] Creating a simple 1-row heatmap

2011-08-08 Thread R. Michael Weylandt
Would the image() function do what you need? n = sample(1:50,25); g = gray(n/max(n)) # set up color palate g = rev(g) # reverse so max is black instead of white image(as.matrix(n),col=g) # Requires a matrix input I think you should be able to handle axes/ labels/ etc as normal:

Re: [R] enclosing with() in a function

2011-08-08 Thread R. Michael Weylandt
Hi Tom, What exactly is this function supposed to do? Your immediate problem is that you are passing it a string x and asking for a mean of the string x (hence complaints that it's not numeric) but I'm a little confused as to what this is supposed to do when it works. If you just want the mean

Re: [R] simple plot question

2011-08-09 Thread R. Michael Weylandt
Hi Maxim, I notice no one has replied to you (on list at least) so I'll take a stab at answering your question and giving some productive advice. I believe the axis command will do what you want with a little tweaking: It certainly lines things up for me. x -

Re: [R] How to get the date of specific value within a zoo object?

2011-08-09 Thread R. Michael Weylandt
I'd suggest you look into the xts class and write require(xts) xts = as.xts(1:5,Sys.Date()+1:5) time(xts)[xts==3] By the way, your code isn't pastable for me: not sure why. Michael Weylandt On Tue, Aug 9, 2011 at 10:39 PM, Richard Ma xuanlong...@uts.edu.au wrote: Hi all, I have a zoo time

Re: [R] How to get the date of specific value within a zoo object?

2011-08-09 Thread R. Michael Weylandt
D'Oh -- just spotted it (don't know what was wrong with me): in your code: 2011-01-05 and ts = zoo(x dt) need to be changed. If you do that, the same trick time(ts)[ts==3] will work. Still, I'm a big xts fan. Michael On Tue, Aug 9, 2011 at 10:45 PM, R. Michael Weylandt michael.weyla

Re: [R] Histograms in R

2011-08-10 Thread R. Michael Weylandt
Perhaps you could shade the bars as appropriate? I'm not going to use your data because it's not an easily paste-able but how about this: x = rnorm(100) y = sample(c(A,B),100,replace=T,prob=c(0.7,0.3)) d = data.frame(level = x, status = y) n = 10 # Number of bins breaks = quantile(d$level,

Re: [R] convert 'list' to 'vector'?

2011-08-10 Thread R. Michael Weylandt
unlist() Michael Weylandt On Wed, Aug 10, 2011 at 2:58 PM, Liviu Andronic landronim...@gmail.comwrote: Dear all How does one convert a non-symmetric list to a vector? See below: x - list() x[[1]] - letters[1:5] x[[2]] - letters[6:10] x[[3]] - letters[11:12] x [[1]] [1] a b c d e

Re: [R] choosing selective data with permutations

2011-08-10 Thread R. Michael Weylandt
To pick random elements to sample, you can just use the sample function sample(1:5,3,replace=T/F) # pick true or false as needed for your data. If you replicate this, you should have no problem. replicate(100,function() return(sample(1:5,3,replace=T/F))) This will be plenty fast, but if you

Re: [R] choosing selective data with permutations

2011-08-10 Thread R. Michael Weylandt
Sorry, that second line of code won't work: do it in 2. f - function() {return(sample(1:5,3,replace=T/F))} replicate(100,f()) Michael On Wed, Aug 10, 2011 at 3:06 PM, R. Michael Weylandt michael.weyla...@gmail.com wrote: To pick random elements to sample, you can just use the sample

Re: [R] generate two sets of random numbers that are correlated

2011-08-11 Thread R. Michael Weylandt
Well, without saying what sort of random numbers you mean, it's a little hard, but here's one straightforward way to do it for 2 normally distributed rvs. X1 = rnorm(100) X2 = rnorm(100) Y = X1 Z = 0.4*X1+sqrt(1-0.4)*X2 then cor(Y,Z) ~ 0.4 In function terms: CorrNorm - function(n=100, rho =

Re: [R] Splitting data

2011-08-11 Thread R. Michael Weylandt
This sounds very much like a recursive problem: something like this seems to get the gist of what you want. DataSplits - function(Data, alpha = 0.05) { DataSplitsCore - function(Data, alpha, level) { tt - t.test(Data[,1],Data[,2]) print(tt) if (tt$p.value alpha) {

Re: [R] help with loops

2011-08-11 Thread R. Michael Weylandt
unlist() Michael Weylandt On Thu, Aug 11, 2011 at 12:46 PM, Srinivas Iyyer srini_iyyer_...@yahoo.comwrote: hi I need help with list object. I have a list object a - c('apple','orange','grape') b - c('car','truck','jeep') c - list(a,b) names(c) - c('fruit','vehicle') c $fruit [1]

Re: [R] 2-dim density plot

2011-08-11 Thread R. Michael Weylandt
I'd suggest either a color plot as given by image() and related functions or a 3d mesh-plot which you can get from persp() E.g., x = seq(0,1,by=0.01); y = x z = outer(x,y+1,/) # z = x/(y+1) -- I know that's not a density but you can adapt as necessary filled.contour(x,y,z) persp(x,y,z) There

Re: [R] help with loops

2011-08-11 Thread R. Michael Weylandt
Weylandt michael.weyla...@gmail.com*wrote: From: R. Michael Weylandt michael.weyla...@gmail.com Subject: Re: [R] help with loops To: Srinivas Iyyer srini_iyyer_...@yahoo.com Cc: r-help@r-project.org Date: Thursday, August 11, 2011, 12:49 PM unlist() Michael Weylandt On Thu, Aug 11, 2011

Re: [R] sapply( ) a loop function

2011-08-11 Thread R. Michael Weylandt
The previous two posters basically covered everything, but since I'm on the train with not too much to do, here's a more detailed response building on what they said. The following code is shovel-ready and can be pasted directly to your command line if you have your main data frame called d

Re: [R] Splitting data

2011-08-12 Thread R. Michael Weylandt
Yes, that likely is the source of the difference: I'm happy to help fix it up (won't be hard), but I want to clarify exactly how you want the data done: say we have 20 variables x = 1:20 if there's a split we go to 1:10, 11:20; then 1:5, 6:10, 11:15,16:20 etc but what about situations with very

Re: [R] Splitting data

2011-08-12 Thread R. Michael Weylandt
Hmmm, interesting problem. I now see your motivation for not using a data frame set up in the split code: try this -- DataSplits - function(Data, alpha = 0.05) { DataSplitsCore - function(Data1,Data2, alpha, level) { tt - t.test(Data1,Data2) print(tt) if (tt$p.value

Re: [R] Splitting data

2011-08-12 Thread R. Michael Weylandt
Sorry -- missed a tweak. The call to DataSplitsCore should read nr = floor(NROW(Data)/2); Data1 = Data[(1:nr)]; Data2 = Data[-(1:nr)]; DataSplitsCore(Data1,Data2,alpha,level) On Fri, Aug 12, 2011 at 11:46 AM, R. Michael Weylandt michael.weyla...@gmail.com wrote: Hmmm, interesting problem. I

Re: [R] Own R function doubt

2011-08-13 Thread R. Michael Weylandt
It sounds like the data frame produced by Simulate() doesn't set the names you want. You can probably fix this by including colnames(Gestion) c(B,T1,... # etc) immediately after the simulation. Can't confirm this without knowing which of the excel/R interface packages you're using, but I'd be

Re: [R] Plotting and quantiles

2011-08-13 Thread R. Michael Weylandt
I believe you received an informative answer to both these questions from Daniel Maiter one hour and twenty five minutes after sending your question: I repeat it here just in case you didn't get it. -- Q1 is very opaque because you are not even saying what kind of plot

Re: [R] Plotting and quantiles

2011-08-14 Thread R. Michael Weylandt
to plot all the data in a line plot - exactly how it is shown in the attached graph. Mark From: R. Michael Weylandt michael.weyla...@gmail.com To: Mark D. d.mar...@ymail.com Cc: r-help@r-project.org r-help@r-project.org Sent: Saturday, 13 August 2011, 21

Re: [R] Plot from function

2011-08-15 Thread R. Michael Weylandt
I believe it's a problem in your variable name hsa-miR-98. R wants to interpret that as hsa less miR less 98. Since you don't have a variable called hsa, R (rightly) complains. Call ls() and see what R thinks your variables are named -- that will hopefully make the problem evident. Hope this

Re: [R] MCMC regress, using runif()

2011-08-15 Thread R. Michael Weylandt
Two things, 1) You need to use square brackets in this case because model is an object, not a function. 2) You probably want to use a list object to store a whole bunch of model objects so you'll want double brackets. model = list(NULL) for (i in 1:1000) { model[[i]] - lm(Y~X1+X2()) } This,

Re: [R] Extracting information from lm results (multiple model runs)

2011-08-15 Thread R. Michael Weylandt
I can't help with the questions on pooling regressions, but for the question about data-frame usage, I'll note two things. One, x = data.frame(y = 1:3, z = 4:6) is.data.frame(x) TRUE is.data.frame(t(x)) FALSE is.data.frame(as.data.frame(t(x))) TRUE Two, you'll need to check that your row

Re: [R] Extracting information from lm results (multiple model runs)

2011-08-15 Thread R. Michael Weylandt
be a special handling of names with brackets. /johannes Original-Nachricht Datum: Mon, 15 Aug 2011 09:39:47 -0400 Von: R. Michael Weylandt michael.weyla...@gmail.com An: Johannes Radinger jradin...@gmx.at CC: r-help@r-project.org Betreff: Re: [R] Extracting information

Re: [R] too many var in lm

2011-08-17 Thread R. Michael Weylandt
The most elegant solution is going to depend on where you data comes from, but one way to do it if you have a matrix of data: D = cbind(rcauchy(100), matrix(runif(100*50),ncol=50)) # Some nonsense data lm(D[,1] ~ D[,-1]) If you let us know how your data is set up, a more specific response can be

Re: [R] Chi square test on data frame

2011-08-17 Thread R. Michael Weylandt
I think everything below is right, but it's all a little helter-skelter so take it with a grain of salt: First things first, make your data with dput() for the list. Y = structure(c(0, 35, 0, 0, 0, 0, 84, 84, 0, 48, 84, 0, 22, 0, 0, 0, 0, 0, 10, 0, 48, 0, 0, 48, 0, 22, 0, 0, 0, 0, 84, 84, 0, 48,

Re: [R] Chi square test on data frame

2011-08-18 Thread R. Michael Weylandt
please help me with this. Thanking you, Warm Regards Vikas Bansal Msc Bioinformatics Kings College London From: R. Michael Weylandt [michael.weyla...@gmail.com] Sent: Wednesday, August 17, 2011 7:11 PM To: Bansal, Vikas Cc: r-help@r

Re: [R] Concatenate two strings in one in a string matrix

2011-08-18 Thread R. Michael Weylandt
Assuming that the * in your [11,] example is a typo, would this work? apply(out$desc,1,paste,collapse=) Hope this helps, Michael Weylandt On Thu, Aug 18, 2011 at 2:35 PM, Eduardo Mendes emammen...@gmail.comwrote: Dear R-Users I have the following matrix out$desc [,1]

Re: [R] Leading zeros

2011-08-19 Thread R. Michael Weylandt
There is a strsplit() function (syntax is (stringToBeSplit, splitAt) ) that may be of use. I haven't followed the thread so I don't know how well it handles the original problem. Michael Weylandt On Fri, Aug 19, 2011 at 12:41 PM, Ole Peter Smith ole@gmail.com wrote: -- Forwarded

Re: [R] d, p, q, r - What are the math relations with each other of this functions?

2011-08-22 Thread R. Michael Weylandt
Read the documentation by typing ?qexp (or whatever other function) at the command line. But, since you asked and it won't take long to answer, the general pattern is: rDIST gives random numbers sampled from the distribution dDIST gives the PDF pDIST gives the CDF qDIST gives the quantile

Re: [R] Extracting columns with specific string in their names

2011-08-22 Thread R. Michael Weylandt
Can you say a little more about what you mean it does not work? I'd guess you have a regular expression mistake and are probably getting more columns than desired, but without an example, it's hard to be certain. Use dput() and head() to give a small cut-and-paste-able example. Michael On Mon,

Re: [R] test if vector contains elements of another vector (disregarding the position)

2011-08-22 Thread R. Michael Weylandt
%in% Here, i %in% j Hope this helps, Michael On Mon, Aug 22, 2011 at 11:51 AM, Martin Batholdy batho...@googlemail.comwrote: Hi, I have the following problem: I have two vectors: i - c('a','c','g','h','b','d','f','k','l','e','i') j - c('a', 'b', 'c') now I would like to

Re: [R] select columns array2 not equal to 10

2011-08-22 Thread R. Michael Weylandt
I want to select the array columns that are not equal to 10. is ambiguous to me. Just to clarify, do you want to simply drop the column named array10 or do you want to check each column for having one/all 10's as values and drop based on that test? Michael On Mon, Aug 22, 2011 at 12:35 PM,

Re: [R] select columns array2 not equal to 10

2011-08-22 Thread R. Michael Weylandt
, Michael, What I want to do is remove all the rows, for which array1, array2, ..array15 are all equal to 10. I want to keep all the rows at least one of the array variables are not equal to 10. sorry for the confusion. On Mon, Aug 22, 2011 at 9:52 AM, R. Michael Weylandt michael.weyla

Re: [R] select columns array2 not equal to 10

2011-08-22 Thread R. Michael Weylandt
(x){any (x != 10), here x is a vector, x!=10 will give a vector of logical value, right? If it is, how can vector be compared to a scale, 10 in this case? Thanks! On Mon, Aug 22, 2011 at 10:16 AM, R. Michael Weylandt michael.weyla...@gmail.com wrote: This isn't the most beautiful code

Re: [R] CDFs

2011-08-22 Thread R. Michael Weylandt
Number 1 can be done as follows: x = rnorm(50); y = rnorm(50) xCDF = ecdf(x); yCDF = ecdf(y) plot(xCDF) lines(yCDF,col=2) For the other ones, you are going to have to be a little more specific as to how you want to do the approximation...but ?density might be a place to start for #4, assuming

Re: [R] CDFs

2011-08-22 Thread R. Michael Weylandt
)? Can ecdf do this? On Mon, Aug 22, 2011 at 2:24 PM, R. Michael Weylandt michael.weyla...@gmail.com wrote: Number 1 can be done as follows: x = rnorm(50); y = rnorm(50) xCDF = ecdf(x); yCDF = ecdf(y) plot(xCDF) lines(yCDF,col=2) For the other ones, you are going to have to be a little

Re: [R] CDFs

2011-08-22 Thread R. Michael Weylandt
On Mon, Aug 22, 2011 at 4:57 PM, David Winsemius dwinsem...@comcast.netwrote: On Aug 22, 2011, at 4:34 PM, David Winsemius wrote: On Aug 22, 2011, at 3:50 PM, R. Michael Weylandt wrote: Yes. The xCDF/yCDF objects that are returned by the ecdf function can be called like functions

Re: [R] Sequence

2011-08-22 Thread R. Michael Weylandt
Two general R tips: 1) Don't name variables seq or var. These are two really important R functions and you can get all sorts of unexpected craziness if you overload them. Going forward, also watch out for t,c, T, F as well. 2) As others have noted, it's very possible to implement this without an

Re: [R] Duplicate Rows in xts

2011-08-22 Thread R. Michael Weylandt
Without example code or data I can't guarantee this is your problem, but have you looked at using xts(...,unique = F) instead of the default true. Alternatively, let us see what your data actually looks like to R (dput) and we'll help. But what you've got sounds like a problem in the date format,

Re: [R] CDFs

2011-08-22 Thread R. Michael Weylandt
On Mon, Aug 22, 2011 at 7:17 PM, David Winsemius dwinsem...@comcast.netwrote: On Aug 22, 2011, at 6:26 PM, R. Michael Weylandt wrote: On Mon, Aug 22, 2011 at 4:57 PM, David Winsemius dwinsem...@comcast.net wrote: On Aug 22, 2011, at 4:34 PM, David Winsemius wrote: On Aug 22, 2011

Re: [R] [r] histogram with mean for every break

2011-08-23 Thread R. Michael Weylandt
I do not believe your code (minimal as it is) would work: the correct argument is breaks. More generally, do you really mean to say that hist(x, breaks = 20) immediately returns the bin counts? It doesn't on my machine and if you knew how to get the counts, you should be able to get the midpoints

Re: [R] Bug or feature? sum(c(a, b, c)) != (a + b + c)

2011-08-23 Thread R. Michael Weylandt
Not directly related to what you said below, but might I suggest that for numerical work all.equal() might be a little more robust in a computationally heavy implementation. x = c(0.812672,0.916541,0.797810) #dont' call variables c -- just a bad idea y = x[1]+x[2]+x[3] sum(x) ==y [1] FALSE

Re: [R] Help: find the index of the minimum of entries

2011-08-24 Thread R. Michael Weylandt
which.min() more generally which(a==min(a)) Michael Weylandt On Wed, Aug 24, 2011 at 12:03 PM, Chee Chen chee.c...@yahoo.com wrote: Dear All, I would like to ask a question on how to find the index of the minimum of entries of a numeric vector, without using loops or user defined

Re: [R] Help: convert entry of a list into a matrix

2011-08-24 Thread R. Michael Weylandt
I'm not sure I understand your question: a[[2]] is a matrix. a - list(matrix(1:6,2),matrix(5:10,2)) is.matrix(a[[2]]) TRUE x = a[[2]] is.matrix(x) TRUE x+2 [,1] [,2] [,3] [1,] 7 9 11 [2,] 810 12 a[[2]] + 2 [,1] [,2] [,3] [1,] 7 9 11 [2,] 810 12 What

Re: [R] Help: convert entry of a list into a matrix

2011-08-24 Thread R. Michael Weylandt
unlist the sub-lists and that gives you a list of matrices, which, as I said before, are matrices when subsetted with `[[`, but not `[`. Michael On Wed, Aug 24, 2011 at 2:37 PM, R. Michael Weylandt michael.weyla...@gmail.com wrote: I'm not sure I understand your question: a[[2]] is a matrix

Re: [R] Column of probabilities

2011-08-24 Thread R. Michael Weylandt
If your numbers are all positive integers, this should work: (tabulate(xm)[xm])/length(xm) it can be put into a function for ease of use: probVec - function(x) {(tabulate(x)[x])/length(x)} You'll have some trouble if you have non-positive integers or non-integers. Let me know if you need to

Re: [R] regarding changing of title of decompose graph

2011-08-24 Thread R. Michael Weylandt
Read the plot documentation by typing ?plot, particularly the optional argument main. Hope this helps, Michael Weylandt On Wed, Aug 24, 2011 at 1:40 PM, upani1982 upananda.p...@gmail.com wrote: Hi All, I am new to this forum. I have just started learning R. When i use plot(decompose(x)), i

Re: [R] unused argument(s) (Header = True) help!

2011-08-24 Thread R. Michael Weylandt
The proper command is header = TRUE capitalization is important for both *h*eader and T*RUE* Hope this helps, Michael Weylandt On Wed, Aug 24, 2011 at 11:10 AM, shardman samuelhard...@hotmail.comwrote: Hi, I'm really new to R so I aoplogise if this is a stupid question. I'm trying to

Re: [R] dput data frame

2011-08-24 Thread R. Michael Weylandt
How are you storing the elements of the data frame? I'm working with a data frame of doubles with no names and having trouble observing the same problem. If they are factor levels though, that *might* account for it. sessionInfo() might also help. Obviously it's not convenient to print this

Re: [R] {R} How to extract correctly from vector?

2011-08-25 Thread R. Michael Weylandt
It sounds like if you know you can pass the string A1 where you need it to go, the command get() *might* be what you are looking for. Also, you can make your code much faster/prettier because R is smart about recycling vectors of different lengths: char - paste(A,1:10, sep=) x - paste(X,1:10,

Re: [R] Segment out of the Graph

2011-08-25 Thread R. Michael Weylandt
Look at ylim, as an optional argument to plot. Michael On Thu, Aug 25, 2011 at 1:07 PM, Claudio Zanettini claudio.zanett...@gmail.com wrote: Hello everyone, I have a graph and a segment parallel to the x axis at y=-10, x=0, and bars on it. Now the question is, Is there a way to leave

Re: [R] Segment out of the Graph

2011-08-25 Thread R. Michael Weylandt
, 1.03*max(y)) or something similar. Michael Weylandt On Thu, Aug 25, 2011 at 1:12 PM, Claudio Zanettini claudio.zanett...@gmail.com wrote: Yes I tried but if I set the lim to 0 then it will not displayed the line that is at -10, right? 2011/8/25 R. Michael Weylandt michael.weyla

Re: [R] Segment out of the Graph

2011-08-25 Thread R. Michael Weylandt
=( 0, 1000) and under it a segment parallel to the x axis at -10. I am sorry it is contorted thing :) Claudio 2011/8/25 R. Michael Weylandt michael.weyla...@gmail.com lim is not the argument: ylim is. You put in a vector of length 2 comprising the min and max y you wish: consider this: x

Re: [R] Adding a normal density curve over the empirical curve

2011-08-25 Thread R. Michael Weylandt
I'm not going to download your data since it's probably irrelevant to your problem and I have no interest in downloading unknown files. Consider this instead: library(quantmod) SPY = getSymbols(SPY,auto.assign=F) SPY = weeklyReturn(Ad(SPY)) densitySPY = density(SPY) plot(densitySPY,main=Kernel

Re: [R] Using write.table i have a table with two columns i would like to save it as an excel file

2011-08-25 Thread R. Michael Weylandt
I'd suggest you should probably just use the simpler write.csv() function to make a file type that will move much more conveniently between Excel and R. The syntax is: write.csv(ThingBeingSaved, filename.csv) If you only put the file name to write.csv it will be placed in your working

Re: [R] how to match a dataframe and a list

2011-08-25 Thread R. Michael Weylandt
I'd be willing to guess that some combination of match() %in% unlist() will get the job done, but without knowing what sort of data you have, I can't write example code. If you could, use the dput() function to turn your data into plain text and let us work directly with it to help you out. If

Re: [R] Adding a normal density curve over the empirical curve

2011-08-25 Thread R. Michael Weylandt
There's nothing wrong with leaving in buggy code when there's a bug that you just can't get (assuming it's part of your real code): I only ask for the error message because it saves us a little bit of time if you can let us know what errors you are getting. Anyways, best of luck, Michael On

Re: [R] duplicate 'row.names' are not allowed???

2011-08-25 Thread R. Michael Weylandt
There's a no-homework policy on this list and given that you are sending from a .student account and referencing example assignments, you probably won't get any help. Looking at the given code, it seems like you should get in touch with a TA sooner rather than later though. Best of luck, Michael

Re: [R] Specifying argument values in a function

2011-08-25 Thread R. Michael Weylandt
Hi Sam, The heart of your problem is that you are not using strings in your off statements. Rather, you are calling objects called norm and cumu and R is trying to test those for equality. In the first case, when you get to norm, R tries to call the norm() function, which is the magnitude of a

Re: [R] cbind giving NA's?

2011-08-26 Thread R. Michael Weylandt
Hmm, that's quite puzzling. I don't know but I'd willing to guess the time/date stamps on a,b are more different than the output is leading us to believe. My experience is that there's always more to a time/date object to trick us up than one would expect. If you could, dput() them so we can see

Re: [R] cbind giving NA's?

2011-08-26 Thread R. Michael Weylandt
NA 2010-04-05 7.4040 28.30 2010-04-06 7.3317 28.38 2010-04-07 NA 28.21 2010-04-08 NA 28.31 2010-04-09 NA 28.47 which is probably what you want. Regards Petr Hi On 26 August 2011 03:37, R. Michael Weylandt michael.weyla

Re: [R] Save figure in pdf

2011-08-26 Thread R. Michael Weylandt
I don't have the FactoMineR library so I can't replicate, but it seems that your problem is that you never plot anything. Effectively, your code runs windows() x = 1:5 x and then wondering where your graph is. Add plot(res.pca) and i think your problem will be solved. Michael Weylandt On

Re: [R] Sicherheitszertifikat für R-Pakete unter Windows [Security Certificates for R Packages in Windows]

2011-08-26 Thread R. Michael Weylandt
To save anyone else 30 seconds, here's how google translates the below: Ladies and Gentlemen, I would like to inform me whether there is the possibility of security certificates for R packages are. Sincerely, Christopher W. Weinberger 2011/8/26 Christoph W. Weinberger

Re: [R] Make a function work on an environemnt

2011-08-27 Thread R. Michael Weylandt
Well, here's one way you could do it: # Don't run this unless you really mean it clear - function(){rm(list=ls(.GlobalEnv), envir = .GlobalEnv)} Both calls to .GlobalEnv seem necessary so that both rm() and ls() go everywhere with it. However, this certainly isn't the most useful code because it

Re: [R] How download Yahoo Quote?

2011-08-27 Thread R. Michael Weylandt
Did you install the package quantmod? install.packages(quantmod) Michael On Sat, Aug 27, 2011 at 4:32 PM, Yumin zpx...@gmail.com wrote: Hi Michael: I tried to simplify the code, but still failed. *con - url(http://quote.yahoo.com;) if(!inherits(try(open(con),

Re: [R] How download Yahoo Quote?

2011-08-27 Thread R. Michael Weylandt
What is wrong with the getSymbols(IBM) command I originally suggested to you? Michael On Sat, Aug 27, 2011 at 6:23 PM, Yumin zpx...@gmail.com wrote: Hi Michael: I installed: install. packages(quantmod) and now it accept library(quantmod) sentence. BUT after input: *

Re: [R] How download Yahoo Quote?

2011-08-28 Thread R. Michael Weylandt
I have simplified the code only to download the sp500 index. Perhaps you have, but you haven't provided any of that simplified code so I'm a little skeptical. I do have to say though, if you've managed to do it more efficiently than the 12 characters in getSymbols() you are a far better coder

Re: [R] Function won't permanently assign values to a vector

2011-08-28 Thread R. Michael Weylandt
Two things: It's just a guess as to what your problem is, but functions in R don't usually act on the object that is passed to them, but rather a copy thereof: if you want to keep the values calculated within the function, that's usually done with an assignment statement combined with the

Re: [R] maximum number of subdivisions reached

2011-08-29 Thread R. Michael Weylandt
Can't help, code runs fine on my machine once you change valu to value. Are you sure it fails in a vanilla run of R and isn't caused by any other choices you have made along the way? Michael PS -- Here's the code func - function(y, a, rate, sad){ f3 - function(z){ f1 -

Re: [R] replacing elements of a zoo object

2011-08-29 Thread R. Michael Weylandt
How exactly do you mean it doesn't work? Copied from my GUI: x = zoo(1:5, as.Date('2001-01-01')+1:5) x[as.Date('2001-01-05')] 2001-01-05 4 x[as.Date('2001-01-05')] = 0 x 2001-01-02 2001-01-03 2001-01-04 2001-01-05 2001-01-06 1 2 3 0 5

Re: [R] replacing elements of a zoo object

2011-08-29 Thread R. Michael Weylandt
PM, R. Michael Weylandt michael.weyla...@gmail.com wrote: How exactly do you mean it doesn't work? Copied from my GUI: x = zoo(1:5, as.Date('2001-01-01')+1:5) x[as.Date('2001-01-05')] 2001-01-05 4 x[as.Date('2001-01-05')] = 0 x 2001-01-02 2001-01-03 2001-01-04 2001-01-05 2001

Re: [R] VisualBasic select case commad in R

2011-08-31 Thread R. Michael Weylandt
? switch Might do the job. On Wed, Aug 31, 2011 at 1:27 PM, Antonio Silva aolinto@gmail.comwrote: Hello I'm translating a Visual Basic routine to R. Which command in R is similar to select case in VB? See the example: select case int(AG) case 0, 5, 8, 10 VAR = 37 case 1, 4

Re: [R] subsetting by rows

2011-08-31 Thread R. Michael Weylandt
Suppose your data is called df. df[rowSums(df == P)0,] In short, this tests each element for equality for P, sums the number of Ps found and subsets when that number is 0. Michael On Wed, Aug 31, 2011 at 1:28 PM, Joao Fadista joao.fadi...@med.lu.sewrote: Dear all, I would like to know how

[R] rJava Installation Problems: 'cannot open compressed file 'rJava/DESCRIPTION', probable reason 'No such file or directory''

2011-09-01 Thread R. Michael Weylandt
Good Morning, I'm trying to install the rJava package on a local (work) machine and having some trouble. The following occurred in an RGui session. sessionInfo() R version 2.13.0 (2011-04-13) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=English_United States.1252

Re: [R] Alternatives to integrate?

2011-09-01 Thread R. Michael Weylandt
Mr . ., MASS::area comes to mind but it may be more helpful if you could say what you are looking for / why integrate is not appropriate it is for whatever you are doing. Strictly speaking, I suppose there are all sorts of alternatives to integrate() if you are willing to be really creative and

Re: [R] Alternatives to integrate?

2011-09-01 Thread R. Michael Weylandt
will be gratefull. Thanks in advance. On Thu, Sep 1, 2011 at 10:55 AM, R. Michael Weylandt michael.weyla...@gmail.com wrote: Mr . ., MASS::area comes to mind but it may be more helpful if you could say what you are looking for / why integrate is not appropriate it is for whatever you

Re: [R] Alternatives to integrate?

2011-09-01 Thread R. Michael Weylandt
, appologies for my previous mistake. It was not my intention to blame about integrate. On Thu, Sep 1, 2011 at 11:49 AM, R. Michael Weylandt michael.weyla...@gmail.com wrote: I'm going to try to put this nicely: What you provided is not a problem with integrate. Instead, you provided a rather

Re: [R] Including only a subset of the levels of a factor XXXX

2011-09-01 Thread R. Michael Weylandt
Dropping all occurences of a factor does not drop that level. This actually turns out to be much more useful than it first might appear, but if you really need to get around it, it can be done. Look at this toy example: R x = factor(c(A,B,C,A,B,C,C)) R x [1] A B C A B C C Levels: A B C R x[x !=

  1   2   3   4   5   6   7   8   9   10   >