library(abind)
asub(x, 1, 1)
On Sun, May 26, 2013 at 10:43 AM, Bert Gunter wrote:
> Martin:
>
> Well, assuming I understand, one approach would be to first get the
> dim attribute of the array and then create the appropriate call using
> that:
>
>> z <- array(1:24,dim=2:4)
>> d <- dim(z)
>> ix <-
Hello,
This is about the new "line profiling" feature in R 3.0.0. As I was
testing it, I find the results somewhat disappointing so I'd like to
get your opinion.
I put some poorly written code in a test.R file, here are the contents:
double <- function(x) {
out <- c()
for (i in x) {
out
This should help:
> invisible(gc())
>
> m0 <- memory.size()
> mem.usage <- function(){invisible(gc()); memory.size() - m0}
> Mb.size <- function(x)print(object.size(x), units="Mb")
>
> zz <- data.frame(a=runif(100), b=runif(100))
> mem.usage()
[1] 15.26
> Mb.size(zz)
15.3 Mb
> a <- zz$a
>
see dump() or dput().
On Sun, Jan 29, 2012 at 10:56 AM, Ajay Askoolum wrote:
> Given:
>
> data(AirPassengers)
>
> I get a ts data structure AirPassengers in the workspace.
>
> How can I generate the code that can create that structure? That is, given an
> example of a data structure, is there a
Try this:
mine <- 1:6
table.combos <- matrix(data = 1:12, nrow = 10, ncol = 6, byrow)
row.is.a.match <- apply(table.combos, 1, identical, mine)
match.idx <- which(row.is.a.match)
total.matches <- sum(row.is.a.match)
On Sat, Jan 28, 2012 at 2:10 AM, Jason J. Pitt wrote:
>
> Hi Melissa,
>
> Well,
You can also look at ?Rscript. There are tutorials online for writing such
scripts.
On Sun, Jan 22, 2012 at 9:31 AM, David Winsemius wrote:
>
> On Jan 22, 2012, at 6:01 AM, Ajay Askoolum wrote:
>
> I haven't been able to find an example of using R with interactive =
>> FALSE.
>>
>> How do I star
You said:
<< Lets say I changed the parameters x to 0.123, y to -0.456, z to -999.99
Then I have to save the R script file as
"Experiment_001_x=0.123_y=-0.456_z=-999.99.r"
and the result file as "Experiment_001_x=0.123_y=-0.456_z=-999.99.rData"
>>
I suggest you create instead a "Experiment.r" f
It is well explained here
http://www.burns-stat.com/pages/Tutor/R_inferno.pdf page 67.
On Sat, Jan 21, 2012 at 9:56 PM, Ery Arias-Castro wrote:
> Hello,
>
> This example seems strange to me:
>
> > if (2 > 3) print('Yes'); else print('No')
> Error: unexpected 'else' in " else"
>
> > {if (2 > 3) p
Another possibility:
df$Date[match(1800, df$myvalue)]
match() stops at the first value encountered so it may be a bit faster
than a full subset(), depending on your table size.
Another difference: this approach would return NA if there was no
match, subset(...)[1, ] would trigger an error. Depend
see the 'fill' argument for cat().
On Sun, Jan 15, 2012 at 12:10 PM, Barry Rowlingson
wrote:
> On Sun, Jan 15, 2012 at 4:40 PM, Francisco
> wrote:
>> Hello,
>> I have to write a big sentence with cat() and I would like that R
>> automatically adds a new line when it is needed (when the text arr
>> I tried to be clever by trying get(paste(paste("x", 1:6, sep=""),
>> collapse="+")) but it didn't work.
Maybe you meant something like this:
sapply(paste("x", 1:6, sep=""), function(x)mean(get(x)))
On Mon, Dec 19, 2011 at 2:30 PM, David Winsemius wrote:
>
> On Dec 19, 2011, at 11:00 AM, Pab
try the lsei function from the limSolve package.
On Mon, Dec 19, 2011 at 2:32 PM, Russell2 wrote:
> Dear All
>
> I have a constrained optimisation problem, I want to maximise the following
> function
>
> t(weights) %*% CovarianceMatrix %*% weights
>
> for the weights,
>
> subject to constraints
y(strsplit(x,"/"),length)-1
>
> Cheers,
> Bert
>
> On Thu, Dec 1, 2011 at 7:44 PM, Florent D. wrote:
>> Resending my code, not sure why the linebreaks got eaten:
>>
>>> x <- data.frame(Col1 = c("abc/def", "ghi/jkl/mno"), string
I have this. I have modified your input structure to be a matrix. I
think it is generally recommended to use matrices over data.frames
when your data allows it, i.e., when you only have one type of data,
here character(). Matrices are easier to work with.
x <- matrix( c('BMW', '', '', 'Mercedes
count.slashes, 1))
Col1 Col2
1 abc/def1
2 ghi/jkl/mno 2
On Thu, Dec 1, 2011 at 10:32 PM, Florent D. wrote:
> I used within and vapply:
>
> x <- data.frame(Col1 = c("abc/def", "ghi/jkl/mno"), stringsAsFactors = FALSE)
> count.slashes <- fun
I used within and vapply:
x <- data.frame(Col1 = c("abc/def", "ghi/jkl/mno"), stringsAsFactors = FALSE)
count.slashes <- function(string)sum(unlist(strsplit(string, NULL)) ==
"/")within(x, Col2 <- vapply(Col1, count.slashes, 1))
Col1 Col21 abc/def 12 ghi/jkl/mno 2
On Thu, Dec 1
if you want to store the result in a column of your data.frame:
within(df, Y <- 6*X1+7*X2+8*X3)
On Wed, Nov 30, 2011 at 9:59 AM, David L Carlson wrote:
> Isn't this even easier?
>
>> X1 <- c(1:3)
>> X2 <- c(3, 4, 6)
>> X3 <- c(5, 6, 1)
>> Y <- 6*X1 + 7*X2 + 8*X3
>> Y
> [1] 67 88 68
>
> Or if yo
better (smaller) than you
first (bad) usage.
On Wed, Nov 30, 2011 at 4:16 AM, Diane Bailleul
wrote:
> Le 11/30/2011 2:09 AM, Florent D. a écrit :
>
> Thanks for your answer !
>
>> I also think your last write-up for LogLiketot (using a single
>> argument "par&q
Oh, and your message:
In log(LikeGi(l, i, par[1], par[2])) : NaNs produced
means your LikeGi is returning something negative. Can't take the log of it...
On Tue, Nov 29, 2011 at 8:09 PM, Florent D. wrote:
> I also think your last write-up for LogLiketot (using a single
> argumen
I also think your last write-up for LogLiketot (using a single
argument "par") is the correct approach if you want to feed it to
optim().
So now you have a problem with log(LikeGi(l, i, par[1], par[2])) for
some values of par[1] and par[2].
Where is LikeGi coming from? a package or is it your ow
Forgot to suggest: if labSt is the 1st column in your file, you could
just add "row.names = 1" to your read.csv call.
On Mon, Nov 28, 2011 at 8:06 PM, Florent D. wrote:
> Unlike a data.frame, a matrix can only hold one type of data. Since
> you have a column of characters (
Unlike a data.frame, a matrix can only hold one type of data. Since
you have a column of characters ("labSt") in your original data,
turning it into a matrix will give you a matrix of characters. You can
check it is the case by asking class(DF.m[1,1]).
So you'll have to remove this labSt column be
source("c:\path\... ")
On Sun, Nov 27, 2011 at 9:28 PM, Yen, Steven T wrote:
> Dear All
>
> I inserted a frequently used function (subroutine) right into my
> Rprofile.site which allows me to run it each time-works great. However,
> this approach is obviously suitable for a short function or a s
1)[491:500]
> [1] 482 483 484 485 486 487 488 489 490 491
> --
> David.
>
>
>> Michael
>>
>> On Nov 27, 2011, at 9:05 AM, Michael Kao wrote:
>>
>>> Hi Florent,
>>>
>>> That is great, I was working on solving the recurrence equation a
You can make things a lot faster by using the recurrence equation
y[n] = alpha * (y[n-1]+x[n])
loopRec <- function(x, alpha){
n <- length(x)
y <- numeric(n)
if (n == 0) return(y)
y[1] <- alpha * x[1]
for(i in seq_len(n)[-1]){
y[i] <- alpha * (y[i-1] + x[i])
}
return(y)
The apply function also works with multi-dimensional arrays, I think
this is what you want to achieve using a 3d array:
aaa <- array(NA, dim = c(2, dim(a)))
aaa[1,,] <- a
aaa[2,,] <- a2
apply(aaa, 3, function(x)lm(x[1,]~x[2,]))
__
R-help@r-project.org m
You defined temp as a vector:
> temp <- vector(mode="numeric", length = vl)
but you try to extract from it as if it was a 2d object:
colA <- temp[,compareA]
Maybe you meant to use temp1 instead? More meaningful variable names might
help avoid such mistakes.
On Wed, Aug 3, 2011 at 6:14 PM, Matt
27 matches
Mail list logo