slice.index() in base
On 4/2/2013 9:53 AM, Enrico Bibbona wrote:
Great!
Thanks a lot, Enrico
2013/4/2 Duncan Murdoch
On 02/04/2013 6:36 AM, Enrico Bibbona wrote:
Is there any function that extends to multidimentional arrays the
functionalities of "row" and "col" which are just defined for
slice.index() in base
On 4/2/2013 6:36 AM, Enrico Bibbona wrote:
Is there any function that extends to multidimentional arrays the
functionalities of "row" and "col" which are just defined for matrices?
Thanks, Enrico Bibbona
[[alternative HTML version deleted]]
___
abind() (from package 'abind') can take a list of arrays as its first argument,
so in general, no need for do.call() with abind().
As another poster pointed out, simplify2array() can also be used; while abind()
gives more options regarding which dimension is created and how dimension names
are
x[file.exists(x)])
[1] "C:\\R\\GTK2-Runtime\\bin/zlib1.dll"
>
There are many ways to modify the PATH. To set PATH inside R:
> Sys.setenv(PATH=paste(grep("UNWANTEDPATH", strsplit(Sys.getenv("PATH"),
> ";")[[1]], value=T, invert=T), collapse=&q
into mvbutils, but it would probably be a significant amount
of work.
-- Tony Plate
On 05/31/2010 09:56 PM, Day, Roger S wrote:
Hello Colleagues,
I've recently become a fan of Mark Bravington's mvbutils package for organizing
analysis projects in a tree.
Using cd(), Save(), fix
bove,
try something like this:
for (i in 1:(L-1)) {
dataName <- paste("fData.", i, sep="")
df <- get(dataName)
... do something with data frame df ...
}
You can also give additional arguments to get() to tell it where to look
(pos=,envir=), and wh
ply(d, function(x) if (is(x, "Date")) format(x,
"%m/%d/%Y") else x))
write.table(d1, quote=which(sapply(d, function(x) !is.numeric(x) & !is(x,
"Date"
"ticker" "date" "price"
"1" "IBM" 12/03/2009 120
"2&qu
matrix(str, ncol=1)
Francesco Napolitano wrote:
Sorry for the dumb question, but I couldn't figure this out myself.
Consider the following:
str <- c("abc","def")
array(str, c(2,1))
[,1]
[1,] "abc"
[2,] "def"
How can i obtain the outcome of the second instruction without
specifying the
Try looking in the NAMESPACE file (in the same directory as the
DESCRIPTION file).
-- Tony Plate
David Scherrer wrote:
Dear all,
I get the error
"Error in namespaceExport(ns, exports) :
undefined exports function1 , function2"
when compiling or even when I roxygen my packag
;more words in front(2)")
grep("[[:alpha:]]+[ \t]*\\([ \t]*[0-9]+[ \t]*\\)", x)
[1] 1 2 3 4 6
grep("^[[:alpha:]]+[ \t]*\\([ \t]*[0-9]+[ \t]*\\)", x)
[1] 1 2 3 4
-- Tony Plate
Dennis Fisher wrote:
Colleagues,
I am using R (2.9.2, all platforms) to search for a
Hyvärinen and Erkki Oja *
(http://www.cis.hut.fi/aapo/papers/IJCNN99_tutorialweb/) -- it's an
excellent introduction.
-- Tony Plate
Joel Fürstenberg-Hägg wrote:
Ok, so then the S gives the individual components, good. Thanks Tony!
But what about the principal components from the PCA
uot;S" (the estimated source matrix) and
"A" (the estimated mixing matrix). Are these what you want?
-- Tony Plate
Joel Fürstenberg-Hägg wrote:
Hi all,
Does anyone know how to get the independent components and loadings from an
Independent Component Analysis (ICA), as well as
long computationally intensive job. And if that's the case, it would make
sense to code it in C.
-- Tony Plate
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
any ideas?
thank you and best regards,
stefan
__
R-help@r-pro
uot;, \"b\"" "\"b\""
row2 "\"c\"""\"d\""
# use R's parsing and evaluation to turn '"a", "b"' into c("a", "b"), and turn
that
# into a matrix containing characte
;=apply(x, 1, function(ab) setdiff(ab[[1]], ab[[2]]
A B A-B
1 Character,2 Character,5 "b"
2 Character,2 Character,5 "g"
3 Character,3 Character,3 Character,3
4 Character,5 Character,3 Character,2
5 Character,2 "i"
e a shortcut for computing the
values of D in the SVD of a matrix -- you could look for that if you have
demanding computations (e.g., the sqrts of the eigen values of the covariance
matrix of scaled x: sqrt(eigen(var(scale(x, center=T, scale=F)),
only.values=T)$values)).
-- Tony Plate
; argument having the value of ls()
Here's an example that doesn't confuse things by having non-standard evaluation
rules:
f <- function(a=1, b=2) cat("a=", a, "b=", b, "\n")
b
Error: object 'b' not found
f(b <- 33)
a= 33 b= 2
b
[1]
x <- matrix(sample(0:1, 1200, replace=T, prob=c(0.952, 0.048)), ncol=30)
table(x)
x
01
1131 69
x <- matrix(sample(0:1, 1200, replace=T, prob=c(0.952, 0.048)), ncol=30)
table(x)
x
01
1151 49
bikemike42 wrote:
Dear All,
I am trying to create an artificial binary matrix
col
a 1 2
b 2 3
cbind(ii, cor=xc[ii])
row colcor
a 1 2 -0.3767034
b 2 3 0.6040273
-- Tony Plate
Lee William wrote:
Hi! All,
I am working on a correlation matrix of 4217x4217 named 'cor_expN'. I wish
to obtain pairs with highest correlation values. So, I
sep="\t")
fit <- lda(c1 ~ v1 + v2 + v3, data=myDat[1:10,])
predict(fit, myDat[11:16,])
$class
[1] c c c b c a
Levels: a b c
...
-- Tony Plate
BostonR wrote:
When I import a simple dataset, run LDA, and then try to use the model to
forecast out of sample data, I get a forecast
, you must add a row to all the
slices. When I read "to add a row in place to a single table of the 3 dimensional
array" it sounds like you might be trying to do something that's not possible with R
arrays. However, if I could see your examples, then I probably give more help.
--
R doesn't access arrays like C, use [i,j] to access a 2-d array, e.g.:
my_array <- array(0,dim=c(2,2))
for(i in seq(1,2,by=1)){
+ for(j in seq(1,2,by=1)){
+ my_array[i,j] = i+j
+ }
+ }
my_array
[,1] [,2]
[1,]23
[2,]34
tdm wrote:
Hi,
Can someone please give m
test$x doesn't evaluate the function, you want something like test(1,2)$x, e.g.:
test <- function(i, j){
x <- i:j
y <- i*j
z <- i/j
return(list(x=x,y=y,z=z))
}
test(1,2)$x
[1] 1 2
test(1,2)$y
[1] 2
test(1,2)$z
[1] 0.5
Or if you want to avoid evaluating y
Try playing around with the "oma" setting in par() -- it sets the outer
margins, which by default are zero.
The following shows the mtext label for me, using the windows device:
par(mfrow=c(2,2))
par("oma")
[1] 0 0 0 0
par("oma"=c(0,0,2,0))
for (i in 1:4) plot(0:1,0:1)
mtext(text = "my test
x <- data.frame(d=letters[1:3], e=letters[3:5])
lookuptable <- c(a="aa", c="cc", e="ee")
match.or.keep <- function(x, lookuptable) {if (is.factor(x)) x <- as.character(x);
m <- match(x, names(lookuptable)); ifelse(is.na(m), x, lookuptable[m])}
# to return a matrix
apply(x, 2, match.or.keep, looku
6, but do be careful of
the gotcha that sample(2:3, ...) will generate a selection of 2's and 3's,
while sample(3,...) will generate samples from 1, 2, and 3.)
-- Tony Plate
Jason Rupert wrote:
Say I have the following data:
house_number<-floor(runif(100, 200, 600))
water_eval
0.52 0.52 0.51 0.51 0.51 0.51 ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr [1:6] "GBP=X.Open" "GBP=X.High" "GBP=X.Low" "GBP=X.Close" ...
Indexed by objects of class: [Date] TZ: GMT
xts Attributes:
List of 2
$ src: chr "yahoo&q
m + smallPosNum) +
bigNegNum). They can also depend on whether intermediate results are kept in
CPU registers, which sometimes have higher precision than 64 bits. Usually,
they're nothing to worry about, which is one of the major reasons that
all.equal() has a non-zero default for the
You could try setting options(error=function() NULL). This should cause R in
batch mode to continue running after an error (the same way it does in
interactive mode.)
-- Tony Plate
Nir Shachaf wrote:
Hi All,
I am running an Rscript with a bunch of algorithms that are UNSTABLE
under some
ind(along=0, x2))
[1] 5 2 2
colSums(abind(along=0, x2))
[,1] [,2]
[1,] 1.768406 -1.534413
[2,] -1.534413 3.890200
-- Tony Plate
megh wrote:
Hi,
I have created a list object like that :
x = vector("list")
for (i in 1:5) x[[i]] = rnorm(2)
x
Now I want to do two th
Did you try putting
library("your-package-name", char=TRUE)
at the start of the examples?
-- Tony Plate
Rebecca Sela wrote:
I am creating an R package. I ran R CMD check on the package, and everything
passed until it tried to run the examples. Then, the result was:
* checkin
ded to whole numbers
x1 <- x
x1$a <- round(x1$a)
merge(x1, y, by=c("a", "b"))
a b c.x c.y
1 1 3 A C
# intersect() returns columns that are the same in each dataframe, not rows
intersect(x, y)
c
1 C
2 D
intersect(x1, y)
a c
1 1 C
2 2 D
-- Ton
wever, it's difficult to diagnose without at least seeing some cut'n'pasted
transcripts. The output of traceback() would also be useful.
-- Tony Plate
Gang Chen wrote:
I've written a function, myFunc, that works fine with myFunc(data,
...), but when I use apply() to run it with an
R doesn't keep track of when objects were created, so that's not possible.
If this is important to you, you could look at the 'trackObjs' package, which
does this and also stores individual objects in individual files (and writes
them to the file when they are changed i
_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] TimeWarp_0.7abind_1.2-0 trackObjs_0.8-0 tap.misc_1.0
[5] bmc.misc_1.0RtTests_0.1-5
-- Tony Plate
Pedro de Barros w
8
[2,]4569 10
)
If none of this is what you want, you could consider storing the matrices in a
list, as another poster suggested.
-- Tony Plate
Suyan Tian wrote:
I am trying to combine two arrays with different dimensions into one.
For example
The first one is
1 2 3
If you return the value as named list, you get your answer
using unlist(res, recursive=F):
> res <- lapply(1:2, function(i) {val <- list(i);
names(val) <- paste("Hugo", i, sep="_"); return(val)})
> unlist(res, rec=F)
$Hugo_1
[1] 1
$Hugo_2
[1] 2
>
Antje wrote:
Oh true, this would solve the
May 23 10:40:01 2008
(I'm sure there are dozens of other ways of doing this, but
the above worked for me.)
-- Tony Plate
--- Edward Wijaya <[EMAIL PROTECTED]> wrote:
You might try cron job under Windows.
http://drupal.org/node/31506
HTH.
- Edward
On Thu, May 22, 2008 at
couldn't see any email contact address on their web page.)
-- Tony Plate
Peter Dalgaard wrote:
Ioannis Dimakos wrote:
Of course it's a virus. Once you catch the virus, you feel this rush,
this fever to abandon all other statistical packages.
On a more serious note, though, the siz
Try this:
> data1 <- list(a = 1, b = 2, c = 3)
> data2 <- list(a = 4, b = 5, c = 6)
> data3 <- list(a = 3, b = 6, c = 9)
> comb <- list(data1 = data1, data2 = data2, data3 = data3)
> sapply(comb, "[[", "a")
data1 data2 data3
1 4 3
> # Also, this can be useful:
> comb[[c("data2", "b")]
If the increases or decreases could be any size,
rle(sign(diff(x))) could do it:
> x <- c(1, 2, 3, 4, 4, 4, 5, 6, 5, 4, 3, 2, 1, 1, 1, 1, 1)
> r <- rle(sign(diff(x)))
> r
Run Length Encoding
lengths: int [1:5] 3 2 2 5 4
values : num [1:5] 1 0 1 -1 0
> i1 <- which(r$lengths==max(r$lengths[r$v
this option to No.
I see 5 identical posts with the subject "Several questions
about MCMClogit" on R-help recently.
-- Tony Plate
j t wrote:
Sorry to bother your.
I am trying to post my question for more than 10 times, but I still
didn't see it.
It drives my crazy!!!
It i
Try something like one of these (as documented in ?formatC)
> formatC(13, flag="0", width=10)
[1] "13"
> sprintf("%010g", 13)
[1] "13"
>
Anh Tran wrote:
Hi,
What's one way to convert an integer to a string with preceding 0's?
such that
'13' becomes '013'
to be put into a
Another way is using straightforward indexing:
> x <- cbind(trips=c(1,3,2), y=1:3, z=4:6)
> x
trips y z
[1,] 1 1 4
[2,] 3 2 5
[3,] 2 3 6
> # generate row indices with the appropriate
> # number of repeats
> ii <- rep(seq(len=nrow(x)), x[,1])
[1] 1 2 2 2 3 3
> # use these indices
If you're using Rgui under Windows, see FAQ 7.1:
7.1 When using Rgui the output to the console seems to be delayed.
This is deliberate: the console output is buffered ...
(the FAQ says how to turn it off -- it's a menu item).
Vidhu Choudhary wrote:
Hi All,
My R code takes very long time to f
lling simpleLoess() with,
and then try calling stats:::simpleLoess() directly. (Of course you have to be
careful with this because this is not using the published API).
-- Tony Plate
Sudipta Sarkar wrote:
Respected R experts,
I am trying to apply a user function that basically calls and
applies
track of those manually.
AFAIK, it's not possible to add some new vars to an existing .RData file --
that's why I wrote the above to save them in a .RData file that's different to
the one that contained the old variables.
-- Tony Plate
Ng Stanley wrote:
> Read and reread, can
bbreviations might break, but it will likely break
quickly and noisily, so it's not too bad (the only case where it wouldn't
break is when fn has a '...' argument itself, and it ignores unrecognized
components, or where the are other argument name collisions).
-- Tony Plate
>
son your attempts with parse() were failing is that default
argument of parse() is a filename (do args(parse) to see this quickly).
You wanted parse(text=...).
-- Tony Plate
Michael Anyadike-Danes wrote:
> R-helpers
>
>
>
> I have 120 small Excel sheets to read and I am usin
?
I'm unsure of their virtue or seediness, but here are some alternatives:
> data.frame(a=numeric(0), b=numeric(0)) # include 9 arguments if you like
[1] a b
<0 rows> (or 0-length row.names)
> as.data.frame(rep(list(a=numeric(0)), 9))
[1] a a.1 a.2 a.3 a.4 a.5 a.6 a.7 a.8
&
(is(obj, "try-error")) return(NA) else return(obj$p.value)
+ }
> my.t.test.p.value(numeric(0))
[1] NA
> my.t.test.p.value(1:10)
[1] 0.000278196
> my.t.test.p.value(1)
[1] NA
> my.t.test.p.value(c(1,1,1))
[1] NA
> my.t.test.p.value(c(1,2,NA))
[1] 0.2048328
>
handle up
to 1 million rows - recent versions prior to 2008 could handle on 64K rows
- see http://en.wikipedia.org/wiki/Microsoft_Excel#Versions ). So, the
suggestion to consult a local statistician is good advice - there may be
other more suitable approaches, and if some form of linear regre
See ?detach, in particular the 'unload' argument and "Details" (issues
involve namespaces & methods, among other things).
Also, note that if the package loaded any compiled code (DLL's in Windows),
some OS's do not support unloading & reloading these.
;undefined columns selected")
so, if a dataframe x has NA values for column names, you should expect
x[...] to *sometimes* stop with that error (with a bit of reading and
testing you could probably work out exactly when that error will occur).
-- Tony Plate
Dieter Menne wrote:
> Dear base
ent.
o Fixed bug that stopped track.stop(all=TRUE) from working
-- Tony Plate
___
R-packages mailing list
[EMAIL PROTECTED]
https://stat.ethz.ch/mailman/listinfo/r-packages
__
R-help@r-project.org mail
---
> ## using text & parse {cheap and dirty} :
> mkseq <- function(i,j) if(i == j) i else paste(i,":",j, sep="")
> parse(text =
> paste("c(", paste(mapply(mkseq, s1,s2), collapse = ","), ")",
Marie Pierre Sylvestre wrote:
> Dear R users,
>
> I am analysing a very large data set and I need to perform several data
> manipulations. The dataset is so big that the only way I can play with it
> without having memory problems (E.g. "cannot allocate vectors of size...")
> is to write a batch s
ot; "stu(2)" "stu(3)"
> parse( text = paste( fun, "(", x, ")", sep = "" ) )
expression(stu(0), stu(1), stu(2), stu(3))
attr(,"srcfile")
>
(Others have observed that in a very large proportion of the situations
where people reach f
nks to Mark Leeds for pointing that out to me in a private message!
(I see this still in the source at
https://svn.r-project.org/R/trunk/src/library/base/man/cbind.Rd -- is that
the right place to look for the latest source to make sure it hasn't been
fixed already?)
-- Tony Plate
ssing 'spectrum' is a data.frame before the code fragment you've shown)
hope this helps,
Tony Plate
Johannes Graumann wrote:
> Why is class(spectrum[["Ion"]]) after this "factor"?
>
> spectrum <- cbind(spectrum,Ion=rep("",
> nrow(spectrum)
ata (Qty), so you're probably storing it in a data frame.
AFAIK, there is no 3d object in R that can store mixed-type data like a
data frame can. An array object in R has to have the same data type for
every column etc.
-- Tony Plate
dave mitchell wrote:
> Dear all,
> Possibly a rudimen
ct(s) are masked from package:base :
format.pval,
round.POSIXt,
trunc.POSIXt,
units
> cut2(x1, g=2)
[1] 1 1 1 1 1 1 1 1 1 2
Levels: 1 2
>
(Additionally, a potentially dangerous peculiarity of quantile() for
this kind of purpose is that its
Try these:
> x <- matrix(rnorm(100), ncol=10)
> persp(x)
> contour(x)
Also, look at the R graph gallery: http://addictedtor.free.fr/graphiques/
-- Tony Plate
threshold wrote:
> Hi All, simple question:
> do you know how to graph the following object/matrix in
c[1] 1 2007-09-07 08:50:58 0 1
> # (TA="total accesses", TW="total writes")
(creation time is tracked too, but not displayed with default settings)
For more info, look in the trackObjs package.
-- Tony Plate
Dong-hyun Oh wrote:
> Dear UseRs,
Mike Waters wrote:
> Tony Plate wrote:
>> [...]
> You don't say if this an R-specific problem, or if it afflicts your
> computer system clock as well.
Thanks, I should have noted that my computer system clock is fine, and as
far as I can tell it (correctly) believes we a
2006-11-10 11:38:47"), "EST5EDT")
[1] "2006-11-10 11:38:47 EST"
>
The problem in 2006 goes away if I set TZ="EST5EDT":
> Sys.setenv(TZ = "EST5EDT")
> Sys.timezone()
[1] "EST"
> as.POSIXlt(as.POSIXct("2006-10-30 11:38:47&q
> a <- c(2, 3, 7, 5)
> b <- c(4, 7, 8, 9)
> mapply(seq, a, b)
[[1]]
[1] 2 3 4
[[2]]
[1] 3 4 5 6 7
[[3]]
[1] 7 8
[[4]]
[1] 5 6 7 8 9
> mapply(sum, a, b)
[1] 6 10 15 14
>
hope this helps,
Tony Plate
Anya Okhmatovskaia wrote:
> Hi,
>
> I am very new to R, s
eople to provide good advice.
> The wiki seems to be riddled with poor practice and "hacks" to get
> around misunderstandings of the way R works.
Is there any way on the R-Wiki for people to quickly and easily add an
annotation indicat
ygwin, but essentially disable use of a particular file. I generally
fix this by resetting ownership and all permissions using Windows
dialogs. It sounds like you need to get your sysadmins to help you sort
this problem out.
-- Tony Plate
Hongxiao Zhu wrote:
> Tony,
>
> Thanks for return.
, I
would suggest posting more details back to the list, e.g., what OS you
are using, and a directory listing that shows file sizes and permissions
(i.e., as you get with 'ls -l' on Unix systems.)
-- Tony Plate
Hongxiao Zhu wrote:
> Hi,
>
> I tried to load a .RData object on unix s
Here's a function that does what I think you want to do:
> attach.firstvar <- function(file) {
+ tmpenv <- new.env()
+ vars <- load(file, envir=tmpenv)
+ x <- get(vars[1], envir=tmpenv, inherits=FALSE)
+ if (is.list(x))
+ attach(x, name=vars[1])
+ return(vars)
+ }
> x
runner wrote:
> In the documentation of 'pairs'(package:graphics), within the last example,
> it reads:
>
> format(c(r, 0.123456789), digits=3)[1]
>
> Why not simple use: format(r, digits=3)? What is the difference?
Here are some examples of the difference:
> for (r in 1.2*10^(-6:9)) cat(form
72 matches
Mail list logo