[EMAIL PROTECTED] wrote:
I have created a list of matrices using sapply or lapply and wish to
extract each of the matrices as a matrix. Some of them are 2x2, 3x3, etc.
I can do this one at a time as:
M1-as.matrix(D[[1]])
How can repeat this process for an unknown number of entries in
If they are already a matrix in the list, then you don't have to use
'as.matrix'; you can just say:
M1 - D[[1]]
Now the question is, what do you mean by how do you index M1? Do you
want to go through the list applying a function to each matrix? If
so, then just 'lapply'. For example, to get
'c' also works with lists:
a=list(1,2,3)
b=list(1,2,3)
c(a,b)
[[1]]
[1] 1
[[2]]
[1] 2
[[3]]
[1] 3
[[4]]
[1] 1
[[5]]
[1] 2
[[6]]
[1] 3
On 7/18/07, elyakhlifi mustapha [EMAIL PROTECTED] wrote:
Hello,
in using vector() we can create a vector and fill in like this
v - vector()
v -
There's no special method, just create a list in the usual way. For example:
l1-list(a=letters[1:5],b=letters[6:10])
l1
$a
[1] a b c d e
$b
[1] f g h i j
l2-list(c=LETTERS[1:5],d=LETTERS[6:10])
l2
$c
[1] A B C D E
$d
[1] F G H I J
l3-list(l1,l2)
l3
[[1]]
[[1]]$a
[1] a b c d e
[[1]]$b
Sure you can.
list(list(), list(), list())
library(fortunes)
fortune(Yoda)
Evelyn Hall: I would like to know how (if) I can extract some of the
information from the summary of my nlme.
Simon Blomberg: This is R. There is no if. Only how.
-- Evelyn Hall and Simon 'Yoda' Blomberg
--- elyakhlifi mustapha [EMAIL PROTECTED]
wrote:
hello,
I wanna know how to create a list of list if it's
possible and if it isn't possible how to do without.
thanks.
Why? The question is not clear and could mean several
things. Can you explain a bit?
try this:
lis. - lapply(lis, function(x) if (length(ind - grep(^IPI, x)))
x[ind[1]] else NULL)
lis.[!sapply(lis., is.null)]
I hope it helps.
Best,
Dimitris
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address:
On Thu, 2007-02-22 at 15:33 +0100, Johannes Graumann wrote:
Hello R-ologists,
[snip]
So:
- if sublist-entry 1 start with ^IPI make it the list-entry.
- otherwise chose the first ^IPI sublist-entry present.
- delete the list-entry if not ^IPI sublist-entry present.
One way to do it would
Thanks for your help!
Joh
Dimitris Rizopoulos wrote:
try this:
lis. - lapply(lis, function(x) if (length(ind - grep(^IPI, x)))
x[ind[1]] else NULL)
lis.[!sapply(lis., is.null)]
I hope it helps.
Best,
Dimitris
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
try something like the following (untested):
objs - ls()
sapply(objs, function(obj) inherits(get(obj), data.frame))
I hope it helps.
Best,
Dimitris
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35,
Is this what you want?
x - list(a=1:3, b=30:34, c=40:35)
x
$a
[1] 1 2 3
$b
[1] 30 31 32 33 34
$c
[1] 40 39 38 37 36 35
lapply(x,'[', 1)
$a
[1] 1
$b
[1] 30
$c
[1] 40
unlist(lapply(x,'[', 1))
a b c
1 30 40
On 9/29/06, Benjamin Otto [EMAIL PROTECTED] wrote:
Hi,
Sorry for the
You need one of the apply family of functions.
?sapply
tmp - list(a=1:2, b=3:5, c=5, dd=numeric(0), e=1:8)
sapply(tmp, function(x) x[1])
a b c dd e
1 3 5 NA 1
__
R-help@stat.math.ethz.ch mailing list
Does this do what you want?
x - list(1,2,3:7,8,9:10)
sapply(x, function(xx) xx[1])
[1] 1 2 3 8 9
-- Tony Plate
Benjamin Otto wrote:
Hi,
Sorry for the question, I know it should be basic knowledge but I'm
struggling for two hours now.
How do I select only the first entry
On Fri, 2006-08-18 at 16:44 -0400, Rajarshi Guha wrote:
Hi, I have a situation where I have a list of lists. Each list can
contain elements of different types (but each one will be a scalar) say
of double, integer or character.
However the elements of each list are always in the same order:
try the following:
arrivals - matrix(sample(1:24, 100, TRUE), 10, 10)
apply(arrivals, 2, function(x) table(factor(x, levels = 1:24)))
I hope it helps.
Best,
Dimitris
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address:
Martin Morgan wrote:
Here's another way:
makeSolver - function() {
f1 - function(x, K) K - x
f2 - function(x, r, K) r * x * f1(x, K)
function() f1(3,4) + f2(1,2,3)
}
solverB - makeSolver()
solverB()
makeSolver (implicitly) creates an environment, installs f1 and f2
into it,
probably you're looking for either
do.call(rbind, lis)
or
do.call(cbind, lis)
where 'lis' is your list.
I hope it helps.
Best,
Dimitris
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven,
Please supply some test data and the expected answer
since its not clear what is desired here.
On 4/5/06, Werner Wernersen [EMAIL PROTECTED] wrote:
Hi,
this is probably the easiest thing to do but I manage
not finding the answer:
I have a list with matrices of exact same format and
headers.
Werner Wernersen pensterfuzzer at yahoo.de writes:
Hi,
this is probably the easiest thing to do but I manage
not finding the answer:
I have a list with matrices of exact same format and
headers. Now I would like to transform the list into
an normal array. What is the proper way to do
On 4/5/06, Ben Bolker [EMAIL PROTECTED] wrote:
Werner Wernersen pensterfuzzer at yahoo.de writes:
Hi,
this is probably the easiest thing to do but I manage
not finding the answer:
I have a list with matrices of exact same format and
headers. Now I would like to transform the list
Oh yes, I should give an example:
m - matrix(1:6,nrow=3)
L - list(m,m)
Output of L:
[[1]]
[,1] [,2]
[1,]14
[2,]25
[3,]36
[[2]]
[,1] [,2]
[1,]14
[2,]25
[3,]36
I would like to transform L to and array looking like
this:
, , 1
[,1]
Grothendieck [EMAIL PROTECTED]
Cc: r-help@stat.math.ethz.ch
Sent: Wednesday, April 05, 2006 3:55 PM
Subject: Re: [R] List to Array
Oh yes, I should give an example:
m - matrix(1:6,nrow=3)
L - list(m,m)
Output of L:
[[1]]
[,1] [,2]
[1,]14
[2,]25
[3,]36
[[2
/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
- Original Message -
From: Werner Wernersen [EMAIL PROTECTED]
To: Gabor Grothendieck [EMAIL PROTECTED]
Cc: r-help@stat.math.ethz.ch
Sent: Wednesday, April 05, 2006 3:55 PM
Subject: Re: [R] List to Array
Oh yes, I
: Wednesday, April 05, 2006 3:55 PM
Subject: Re: [R] List to Array
Oh yes, I should give an example:
m - matrix(1:6,nrow=3)
L - list(m,m)
Output of L:
[[1]]
[,1] [,2]
[1,]14
[2,]25
[3,]36
[[2]]
[,1] [,2]
[1,]14
[2
LD == Liz Dem [EMAIL PROTECTED] writes:
LD I have a list (mode and class are list) in R that is many elements long
and of the form:
length(list)
LD [1] 5778
list[1:4]
LD $ID1
LD [1] num1
LD $ID2
LD [1] num2 num3
LD $ID3
LD [1] num4
LD $ID4
LD
Thx for the hint...
the div - factor(c(1,1,1,2,2)) did exactly what I was expecting...
Stéphane.
Le Mardi 31 Janvier 2006 15:50, Gabor Grothendieck a écrit :
Your post seems to be messed up but I will assume you have a
5 column data frame and the questino is how to run f on the first
three
Your post seems to be messed up but I will assume you have a
5 column data frame and the questino is how to run f on the first
three columns and separately on the last two. I think the
easiest is just the following where I have used the builtin iris
data set where I have assumed that the
This worked great but I'm a bit confused about how to access the names
(keys?) of a list in a loop, and why this is failing for me:
I want to cross the entries in mylist (like entry0001) with the
columns of a dataframe ginput:
$entry0001
[1] AB0032 CF32134 DF34334
$entry0002
[1] AB0033
On 27 Jan 2006, [EMAIL PROTECTED] wrote:
But mylist$entrylabel is not working inside the loop.
'$' doesn't evaluate its argument. You want mylist[[entrylabel]].
I haven't been able to found my way with R lists, maybe because I'm
comparing them with perl's hashes.
R lists do have names, but
The following might be what you want (replace clipboard with your
filename):
mylist - strsplit(readLines(clipboard), :)
nm - sapply(mylist, [, 1)
mylist - lapply(mylist, [, -1)
names(mylist) - nm
mylist - lapply(mylist, function(s) strsplit(s, ,)[[1]])
mylist
$entry0001
[1] AB0032 CF32134
This also depends on which field you are interested in, for example
MEDSTATS (http://tinyurl.com/bwha8)
ED-STATS (http://lists.psu.edu/archives/edstat-l.html)
and a few more http://tinyurl.com/a8wo4
Regards, Adai
On Fri, 2005-09-30 at 07:32 -0500, Marc Schwartz wrote:
On Thu, 2005-09-29
Indeed.
I was not aware of the additional non-usenet statistics Google Groups.
Some familiar names on the MEDSTATS list... :-)
Thanks Adai.
Marc
On Sat, 2005-10-01 at 18:17 +0100, Adaikalavan Ramasamy wrote:
This also depends on which field you are interested in, for example
MEDSTATS
There is some discussion and data sources of the volume of email on
the list in:
http://finzi.psych.upenn.edu/R/Rhelp02a/archive/27532.html
On 9/30/05, José Raul Capablanca [EMAIL PROTECTED] wrote:
Dear All,
How can I can to know a mail list , to speak about
exclusively statistic. Thanks.
José Raul Capablanca wrote:
Dear All,
How can I can to know a mail list , to speak about
exclusively statistic. Thanks.
Hola Jose,
If you mean a list devoted exclusively to statistics
(Si desea una lista solo para la statistica)
http://www.jiscmail.ac.uk/lists/allstat.html
(y una lista
On 30-Sep-05 Jim Lemon wrote:
José Raul Capablanca wrote:
Dear All,
How can I can to know a mail list , to speak about
exclusively statistic. Thanks.
Hola Jose,
If you mean a list devoted exclusively to statistics
(Si desea una lista solo para la statistica)
On Thu, 2005-09-29 at 23:47 -0500, José Raul Capablanca wrote:
Dear All,
How can I can to know a mail list , to speak about
exclusively statistic. Thanks.
If you have access to Usenet either via an NNTP server or via Google
Groups, there are three principal groups for general statistics
[EMAIL PROTECTED] wrote:
In this simple function, how can I pass strings for index and column names
to the function? I've posted this type of question before and received no
response.
Maybe this example will be easier to understand and troubleshoot.
ds - function(myds, vec)
I wrote a function that created the crosstab and removed the extraneous lines
and then used lapply
aestabs - function(x){
temp - xtabs(psn ~ lga + year,x)
temp - temp[rowSums(temp) != 0,]
return(temp)
}
eas2 - lapply(split(ipi$eas,ipi$eas$RegionNum),aestabs)
It's not really
Re-Hello frederic,
Don't worry, i have the same english speaking problem, here is what i
suggest :
n - natScan()
natScan - function(){
cat(\n)
cat(Give me a natural (everything after the '.' will be ignored)\n)
n - scan(,
On Mon, 27 Dec 2004 03:18:53 -0800 (PST)
Frederic renaud [EMAIL PROTECTED] wrote:
Hello
I've another question :-)
I would like to transform a list to a integer.
I must be sure that the number entered by the user is
an integer! Thus, I've made :
repeat{
cat(Effectif des populations
From: Karla Sartor
Hello all,
As a general programming question I can't seem to figure out
how to make
a list of lists in R.
As matrices won't work as they have to be rectangular.
I am sure that there is an easy solution but...
the specific situation is this:
- I have created a
Is the following more like what you want:
a=c(1,1,1,1,1) # generate the first list
b=c(2,2,2)# generate a second list
d=list(a,b)# make a list of a and b
(
e=c(d,a)
)
[[1]]
[1] 1 1 1 1 1
[[2]]
[1] 2 2 2
[[3]]
[1] 1
[[4]]
[1] 1
Hi Valery,
a simple way to do it might be the following:
lis - list(a=10, b=20, d=x)
e1 - new.env()
for(i in 1:length(lis)) assign(names(lis)[i], lis[[i]], envir=e1)
d
get(d, env=e1)
I hope it helps.
Best,
Dimitris
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public
I don't get the same result, do you have a package loaded that would change
the default behavior (such as Hmisc)?
list(grp.1)
[[1]]
[1] 1 2
Levels: 1 2
list(grp.1[mask])
[[1]]
[1] 1
Levels: 1 2
library(Hmisc)
snip
list(grp.1[mask])
[[1]]
[1] 1
Levels: 1
--Matt
version
_
Andrew Robinson wrote:
Greetings R community,
I am curious about the following behaviour: if I define a factor, and
then store a subset of it in a list, the stored version seems to drop
levels that were not included in the subset. E.g. ..
mask - c(T, F)
grp.1 - factor(c(1,2))
list(grp.1)
[[1]]
Matt,
very astute - thanks. I did indeed have Hmisc loaded.
Andrew
On Tue, Nov 09, 2004 at 08:12:57PM -0800, Austin, Matt wrote:
I don't get the same result, do you have a package loaded that would change
the default behavior (such as Hmisc)?
list(grp.1)
[[1]]
[1] 1 2
Levels: 1 2
On Thu, 4 Nov 2004, Adaikalavan Ramasamy wrote:
Sorry if this is a question more on regular expressions. I am dealing
with several files which have been badly named. For example the files
are given either the extensions txt, TXT or Txt. I wish to select all
those files ending with 'txt'
Thanks to Sundar Dorai-Raj, Prof. Ripley and Berton Gunter for the
solution. I think I will take Prof. Ripley's suggestion and stick with
my initial solution for code readability but I am sure the regexp stuff
will come handy next time.
On Thu, 2004-11-04 at 15:10, Prof Brian Ripley wrote:
On
White, Charles E WRAIR-Wash DC wrote:
It is frustrating to see the labels I want in the dimensions of a list but not be able to extract those labels into titles for plots generated from component objects. If someone could set me straight, I would appreciate it. For your amusement, I have provided
My goal is more efficient code for something I anticipate doing a lot.
My example code from my first message works because I insert a seemingly
redundant recording of Dose Treatment in the list generated in the
by command. Since Dose Treatment are already recorded in the
dimensions of the list,
From: Luis Rideau Cruz
R-help,
I have a list of several data frames.
I want to compute the rowSums of the columns of these data
frames but first one.
Something like this
lapply(my.list,rowSums)
You're almost there:
lapply(my.list, function(x)
Luis Rideau Cruz wrote:
R-help,
I have a list of several data frames.
I want to compute the rowSums of the columns of these data frames but first one.
... but first data.frame or but first column?
but first data.frame:
lapply(my.list[-1], rowSums)
but first column:
lapply(my.list, function(x)
Hi Luis,
maybe there are better ways but you could try something like this,
n - length(frame)
lapply(split(frame, frame$Year), function(x, n.){
res - numeric(n.-2)
for(i in 3:n.) res[i-2] - sum(x$Total[x[,i]0.])
res
}, n.=n)
I hope this helps.
Best,
Dimitris
Dimitris Rizopoulos
This is also the sort of thing tapply() does well: (note that by() and
aggregate() are just fancy wrappers for tapply).
e.g.
tus-tapply(yourframe$Total,list(yourframe$Year,yourframe$Tus0),sum)
(One could nest this within an lapply() to loop over the different columns of
your frame).
Note that
Meinhard Ploner wrote:
how can I get a list of all S3-methods (of a package)
such that I know which functions to include in the S3method()
in the NAMESPACE-file?
Maybe separated by generic=T/F.
thx
Meinhard Ploner
Vienna
Since one you does not register S3 methods (except for the Namespace
file),
Meinhard Ploner wrote:
how can I get a list of all S3-methods (of a package)
such that I know which functions to include in the S3method()
in the NAMESPACE-file?
Maybe separated by generic=T/F.
thx
Meinhard Ploner
Vienna
Since one you does not register S3 methods (except for the Namespace
file),
Meinhard Ploner wrote:
Meinhard Ploner wrote:
how can I get a list of all S3-methods (of a package)
such that I know which functions to include in the S3method()
in the NAMESPACE-file?
Maybe separated by generic=T/F.
thx
Meinhard Ploner
Vienna
Since one you does not register S3 methods (except
UweL == Uwe Ligges [EMAIL PROTECTED]
on Wed, 14 Jul 2004 11:25:20 +0200 writes:
UweL Meinhard Ploner wrote:
how can I get a list of all S3-methods (of a package)
such that I know which functions to include in the
S3method() in the NAMESPACE-file? Maybe separated by
?mapply, but I think what you are doing is as good as anything.
On Thu, 1 Jul 2004, Rajarshi Guha wrote:
I have a list in which element is a vector (all of the same length and
all numeric). I want to find the mean of the first elements of the
vectors, the mean of the second elements of the
Here are three solutions but I think the original idea of just
converting to a data frame and using rowMeans (last solution) is simplest:
L - list(1:5, 6:10) # test list
do.call(mapply, c(sum,L)) / length(L)
sapply(seq(along=L),function(i)mean(sapply(L,[[,i)))
rowMeans(as.data.frame(L))
Have you considered lapply(by(...), ...)? The help for by includes
an example using sapply. See also Venables and Ripley, Modern Applied
Statistics with S.
hope this helps. spencer graves
Christian Schulz wrote:
Hi,
have anybody a hint /starting point how i can
enlarge my code that's
[EMAIL PROTECTED] writes:
Hi,
I would like to create a list of data frames that I could access via index
manipulation. An array pointer of dataframe...
for (i in 1:length(InputFilelist))
{
# create data.frame
temp - read.table (file = InputFilelist[i] , header = T, skip = 4)
[EMAIL PROTECTED] wrote:
Hi,
I would like to create a list of data frames that I could access via index
manipulation. An array pointer of dataframe...
for (i in 1:length(InputFilelist))
{
# create data.frame
temp - read.table (file = InputFilelist[i] , header = T, skip = 4)
#
Thank you!!!
all the answers were really useful!!! and taught me something different!!
Gabriela
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
How about the following:
AList - vector(mode=list, length=3)
for(i in 1:3){
y - df[,i])
mod - lm(y~Tr*Dose, data=x, contrasts=list(Tr=contr.sum, Dose=contr.sum))
AList[[i]] - Anova(mod, type=III)
}
hope this helps. spencer graves
CENDOYA, Gabriela wrote:
Hi R-Helpers:
Im trying to fit the same
Peter Dalgaard [EMAIL PROTECTED] writes:
CENDOYA, Gabriela [EMAIL PROTECTED] writes:
for (myname in names(myframe)){
mycall - substitute(lm(myvar~etc.etc.),list(myvar=as.name(myname)))
myfit - eval(mycall)
print(summary(myfit))
} ## by Peter Dalgaard
But instead of
Eryk -
Question 1: Square brackets work, just the same as for
vectors, and return a (smaller or larger) list object.
The new thing with lists, not available (or needed) with
vectors, is double square brackets, which return one list
element as itself, not enclosed in a list.
See
On Fri, 19 Sep 2003, Wolski wrote:
The second problem i have are that i want to store parmeters to the plot.default
function in a list. eg.: pars-list(xlim=c(0,100),xlab=irrelevant ,
ylab=incredible important).
and call the plot.default function with this list as parameters.
I know that
Jesper Runge Madsen [EMAIL PROTECTED] writes:
Dear R helpers
I am trying to convert a list into a data frame but when I try, I get a
stack overflow error (Error: protect(): stack overflow). My list contains
about 17000 rows and looks like shown at the bottom. The reason that I
want to
Jesper Runge Madsen wrote:
Dear R helpers
I am trying to convert a list into a data frame but when I try, I get a
stack overflow error (Error: protect(): stack overflow). My list contains
about 17000 rows and looks like shown at the bottom. The reason that I
want to convert it in to a data frame
Many thanks (I'm sure from all of us) to Martin Maechler for
taking time at a late hour on Friday evening to resolve the
delays on the R server at ethz.ch (hypatia).
Hypatia (cunning minx) waited till his back was turned before
settling down to do her worst.
However, all seems to be well now, so
71 matches
Mail list logo