Displaying 20 results from an estimated 171 matches for "alist".
Did you mean:
list
2004 Jan 15
3
Extracting multiple elements from a list
For a long time I've wanted a way to conveniently extract multiple elements
from a list, which [[ doesn't allow. Can anyone suggest an efficient
function to do this? Wouldn't it be a sensible addition to R?
For example,
alist <- list()
alist[[1]] <- list()
alist[[1]]$name <- "first"
alist[[1]]$vec <- 1:4
alist[[2]] <- list()
alist[[2]]$name <- "second"
alist[[2]]$vec <- 5:8
both.vec <- c(alist[[1]]$vec, alist[[2]]$vec)
Can I get both.vec without c() or an explicit loop?
and...
2006 Nov 06
5
alist()
In trying to get NULL members into a list, I found out about alist().
x<-alist()
x$one<-1
x$two<-NULL
but x$two doesn't exist.
It seems, though, that an alist is just a list.
How can one put NULL members into a list?
2009 Nov 19
4
Is there an variant of apply() that does not return anything?
There are a few version of apply() (e.g., lapply(), sapply()). I'm
wondering if there is one that does not return anything but just
silently apply a function to the list argument.
For example, the plot function is applied to each element in 'alist'.
It is redundant to return anything from apply.
apply(alist,function(x){ plot each element of alist})
2008 Oct 01
2
Bug or feature with finding a list element?
This seems odd. When I try to look up a list element which has a space in
the name using just the first word (i.e. no spaces), it will sometimes
return the element with a space in the name and sometimes it will return
NULL.
Try this:
alist <- list( 'hello'=10, bye=20, 'hello world'=30, 'goodbye world'=40, 'hi
world'=50, 'goodbye foo'=60, 'goodbye bar'=70)
Then try fetching some list elements:
> alist[['goodbye']]
NULL
> alist[['hi']]
[1] 50
> alist[['hell...
2003 Nov 13
1
Can't get Sweave syntax highlighting with Emacs
..."ess major mode" t)
(autoload 'ess-noweb-mode "ess" "ess noweb mode" t)
(autoload 'ess-noweb-make-buffer "ess" "open a buffer in R mode" t)
(autoload 'ess-make-buffer "ess" "open a buffer in R mode" t)
(setq auto-mode-alist (append '(("\\.R$" . ess-mode)) auto-mode-alist))
(setq auto-mode-alist (append '(("\\.S$" . ess-mode)) auto-mode-alist))
(setq auto-mode-alist (append '(("\\.sp$" . ess-mode)) auto-mode-alist))
(global-set-key [(f10)] 'ess-make-buffer)
(add-hook ...
2013 Mar 28
2
how to search a list that contains multiple dissimilar vectors?
Dear All,
This is a simple question, but I'm stumped about the simplest way to search a list object such as the following:
This randomish snippet:
n <- c(round(runif(round(runif(1,1,10),0),1,10),0))
alist <- new("list")
for (i in seq_along(n)) {
alist[[i]] <- c(round(runif(round(runif(1,1,10),0),1,10),0))
}
names(alist) <- sample(letters[1:length(n)])
rm(n);c(alist)
...produces something like this:
$d
[1] 4
$b
[1] 3 5 3
$a
[1] 2 5 7 3 10 3 4 9 9
$c
[1] 6 3 7 4...
2009 Dec 30
1
What am I doing wrong in my loops?
...ot; "5" "6" "7" "8" "9" "10" "11" "12" "13"
"14" "15"
[16] "16" "17" "18" "19" "20" "21" "22" "23"
> alist
$`0`
[1] 3 10 10 6 5 6 4 8 9 3 7 5 8 3 6 7 2 6 6 1 4 8
10 4 10
[26] 13 6 2 8 4 7 3 4 7 9 6 4 7 4 4 4 3
$`1`
[1] 1 1 3 2 3 4 2 1
$`2`
[1] 1 1 3 3
. . .
mn=c(length(alist)*1000)
il=c(length(alist)*1000)
# Now calculate the means
for(i in 1:length(alist)) {
for...
2006 May 27
0
Correction to ?alist (PR#8904)
Hi, people. ?alist says:
'alist' is like 'list', except in the handling of tagged arguments
with no value.
As written, this description is misleading. For example:
> list(e=3+5)
$e
[1] 8
> alist(e=3+5)
$e
3 + 5
We are not in the situation of tagged argumen...
2003 Aug 20
0
end-of-loop-timeout problem and submit-bug-report output (resending) (PR#3841)
...nil
ess-keep-dump-files "always"
ess-source-directory "/tmp/"
)
(ess-setq-vars-LOCAL): language=SAS, dialect=SAS, buf=unlikely-name.sas,
comint..echoes=nil, comint..sender=comint-simple-send
(ess-mode-1): ess-language=SAS, ess-dialect=SAS buf=unlikely-name.sas
(ess-mode-1.5): alist=((ess-local-customize-alist quote
SAS-customize-alist) (ess-language . SAS) (ess-dialect . SAS)
(ess-mode-editing-alist . SAS-editing-alist) (ess-mode-syntax-table .
SAS-syntax-table) (inferior-ess-program . inferior-SAS-program-name)
(ess-help-sec-regex . ^[A-Z. ---]+:$) (ess-help-sec-keys-alist ....
2006 Jan 04
17
Scriptaculous + Prototype shrunk to < 50Kb
Maybe I''m anal but I like fat-free JS, so I pulled the Proptotype and core
Scriptaculous files into one single JS file at 49Kb.
It''s "packed" so if you care about that kind of thing, it''s also
"obfuscated".
Download from my personal site at www.alistercameron.com.
- Alister
PS. Of course this is the current version as posted on the Scriptaculous
site.
Alister Cameron
Managing Director
<http://www.cameroncreative.com/images/cc_logo_small.gif>
<http://www.cameroncreative.com/> Cameron Creative
PO Box 4321
<http://m...
2018 Jun 08
3
Subsetting the "ROW"s of an object
...RUE)
mc[[ nd + 3L ]] <- FALSE
names( mc )[ nd+3L ] <- "drop"
eval(mc)
}
Curiously enough the timing is *much* better for this implementation than for the first version I sent.
Constructing a version of `mc' that looks like `x[i,,,,drop=FALSE]' can be done with `alist(a=)' in place of `list(TRUE)' in the earlier version but seems to slow things down noticeably. It requires almost twice (!!) as much time as the version above.
Best,
Chuck
2009 Oct 01
1
inverse currying
Dear list,
I have the following function,
sugar = function(fun, id = "id"){
ff <- formals(fun)
if( id %in% names(ff))
stop("id is part of args(fun)")
formals(fun) <- c(unlist(ff), alist(id=))
fun
}
which one may use on a function foo,
foo = function(x){
x
}
sugar(foo) # results in the extended closure,
function (x, id)
{
x
}
Its limitation (other than not working with .Primitives) is the 'id'
tag that I add in the formals of fun(). I don't know how to crea...
2001 Oct 16
4
Assignment of structures on a given environment
...sing large arguments to functions or
returning values, I'm trying to do the assignment of variables in a
given environment. The problem is when I try to assign a structure: a
list for example.
If I have:
ind <- c("a","b")
my idea is doing something like
l <- alist()
l[ind] <- as.list(c(20,40))
in a given environment.
Example:
ref <- new.env()
(.....)
assign("l",alist(),env=ref)
If I do
assign("l$a",20,env=ref)
it creates me a new variable in the ref environment named "l$a"
So...
2006 Mar 14
3
rails on emacs - need a working .emacs sample
...t a bit more comlex after I got most of the .el files in the articles
http://www.emacswiki.org/cgi-bin/emacs/RubyOnRails -and-
http://wiki.rubyonrails.com/rails/pages/HowToUseEmacsWithRails.
Each of these has a sample of .emacs and I see that some commands may
be duplicated.
eg, (setq auto-mode-alist (cons ''("\\.rhtml$" . html-mode) auto-mode-alist))
and
(add-to-list ''auto-mode-alist ''("\\.rhtml$" . html-mode))
I copied both of these files into my .emacs and have been playing with
commenting out or uncommenting various lines. (Obviously I am not...
2004 Jan 09
1
Call and memory
...mplish my goal?
My code follows:
"mListTest" <-
function(X,N,k) {
.Call("mList",as.double(X),as.integer(N),as.integer(k));
}
SEXP mList(
SEXP Xi,
SEXP Ni,
SEXP ki
)
{
double *pX=NUMERIC_POINTER(Xi);
int N=INTEGER_POINTER(Ni)[0];
int k=INTEGER_POINTER(ki)[0];
SEXP alist;
SEXP avector;
SEXP nvector;
SEXP rvector;
SEXP kvector;
int n;
int i;
transposeMatrix(pX,N,k);
n=4;
PROTECT(alist=NEW_LIST(n));
PROTECT(avector=NEW_NUMERIC(200));
for (i=0;i<200;i++) {
NUMERIC_POINTER(avector)[i]=pX[i];
}
SET_ELEMENT(alist,0,avector);
UNPROTECT(1);
PROTECT(n...
1999 Mar 29
3
problems with formals and get (PR#151)
...ry
test <- function(){
fn <- function(a) print("hello")
print(is.function(fn))
print(names(formals("fn")))}
test()
if fn is not quoted in the last line of test, it works properly.
test <- function(){
fn <- function() print("hello")
formals(fn) <- alist(a=,b=)
return(fn)}
formals(test())
now try with line 3 of test changed to
formals(fn) <- alist(a=)
Jim
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "he...
2005 Feb 28
2
Changing function arguments to NULL
...UN)
}
}
My problem is that sometimes I want to set one of the arguments to NULL.
But trying to set one of the match.call() arguments to NULL causes it to
be ignored (since the match.call() output is coerced into a list). What
I'd like is that the match.call() output could be converted into an
alist, so that tagged values with no arguments could be handled and
passed on to the next function call without being ignored.
However, I haven't been able to figure out how to construct this alist
without knowing ahead of time what all of the function arguments are and
typing them in explicitly:
e....
2009 Mar 22
2
Following progress in a lapply() function
...sort of progress report. For instance, print a dot on the screen every time 1000 item have been process. Or even better, reporting the percent of the list that have been process every 10%. However, I can't seem to figure out a way to achieve that.
For instance, I have a list of 50,000 slots:
aList <- replicate(50000,list(rnorm(50)))
That need to be process through the following custom function:
myFnc <- function(x){
tTest <- t.test(x)
return(list(p.value=tTest$p.value,t.stat=tTest$stat))
}
Using an lapply statement, as in:
myResults <- lapply(aList, myFnc)
The goal...
2007 Oct 16
2
How to speed up multiple for loop over list of data frames
Hi there,
I have a multiple for loop over a list of data frames
for ( i in 1:(N-1) ) {
for ( j in (i+1):N ) {
for ( p in 1:M ) {
v_i[p] = alist[[p]][i,"v"]
v_j[p] = alist[[p]][j,"v"]
}
rho_s = cor(v_i, v_j, method = "spearman")
rho_p = cor(v_i, v_j, method = "pearson" )
iv = c( iv, min(i, j) )
jv = c( jv, max(i, j) )
rh...
2003 Oct 04
0
allocating memory in a C module (fwd)
I pressed ^X in the wrong window. Here's the right code:
Here's some code that does a pointless example
In C:
#include "Rinternals.h"
/* function takes no arguments and returns an object */
SEXP pie(){
int n;
SEXP alist, avector;
/* work out how long a list to return */
n = 2;
/* create the list */
PROTECT(alist = allocVector(VECSXP, n));
/* create the first vector and populate it */
n = 4;
PROTECT(avector = allocVector(INTSXP, n));
INTEGER(avector)[0] = 3;
INTEGER(avector)[1] = 1;
INTEGER(avector)[2]...