Displaying 20 results from an estimated 30000 matches similar to: "how to iterate through a list using ls"
2012 Feb 23
5
cor() on sets of vectors
suppose I have two sets of vectors: x1,x2,...,xN and y1,y2,...,yN.
I want N correlations: cor(x1,y1), cor(x2,y2), ..., cor(xN,yN).
my sets of vectors are arranged as data frames x & y (vector=column):
x <- data.frame(a=rnorm(10),b=rnorm(10),c=rnorm(10))
y <- data.frame(d=rnorm(10),e=rnorm(10),f=rnorm(10))
cor(x,y) returns a _matrix_ of all pairwise correlations:
cor(x,y)
2009 Nov 11
1
How to get the names of list elements when iterating over a list?
I need to get the names of the list elements when I iterate over a
list. I'm wondering how to do so?
alist=list(a=c(1,3),b=c(-1,3),c=c(-2,1))
sapply(alist,function(x){
#need to use the name of x for some subsequent process
})
2013 Mar 07
2
iterative extracting data from a list without keys
Dear R Users.
This seems like a simple task, but I'm stuck.
I have a list with 3 elements: (2 vectors and 1 matrix). I wish to extract each of these data elements using index subscripts and multiply them with a vector multiplier.
What I have:
> betas
[1] 0.01 0.01 0.01
> LData[1]
$int
[1] 1 1 1 1 1 1 1 1 1 1
$date
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]
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)
2007 Sep 01
2
Comparing "transform" to "with"
Hi All,
I've been successfully using the with function for analyses and the
transform function for multiple transformations. Then I thought, why not
use "with" for both? I ran into problems & couldn't figure them out from
help files or books. So I created a simplified version of what I'm
doing:
rm( list=ls() )
x1<-c(1,3,3)
x2<-c(3,2,1)
x3<-c(2,5,2)
2015 Jun 22
6
OT: default password for HP printer
On 06/22/2015 05:14 PM, Fred Smith wrote:
> On Mon, Jun 22, 2015 at 03:52:17PM -0400, ken wrote:
>> On 06/22/2015 02:51 PM, Fred Smith wrote:
>>> On Mon, Jun 22, 2015 at 02:30:00PM -0400, ken wrote:
>>>> On 06/22/2015 12:43 PM, Scott Robbins wrote:
>>>>> On Mon, Jun 22, 2015 at 11:31:34AM -0400, ken wrote:
>>>>>> For some reason the
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"
2008 Dec 22
2
How can I avoid nested 'for' loops or quicken the process?
Hi All,
I'm still pretty new to using R - and I was hoping I might be able to get
some advice as to how to use 'apply' or a similar function instead of using
nested for loops.
Right now I have a script which uses nested for loops similar to this:
i <- 1
for(a in Alpha) { for (b in Beta) { for (c in Gamma) { for (d in Delta) {
for (e in Epsilon)
{
Output[i] <-
2005 Apr 18
1
Storing vectors as vectors and iterating through them
Hi all,
I have a bunch of int vectors. Each vector holds a bunch of ints that
correspond to row numbers of an existing matrix. I use the int vectors to
pull out rows of data from a matrix, i.e.
data <- my_matrix[int_vector,]
I would like to store these int vectors in some sort of data structure that
will preserve them as-is and allow iteration. I guess what I'm looking for
would be
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 <-
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
2019 Oct 26
2
ls permissions format changed in CentOS 8
Found it. It happens from the process buffer inside Lugaru Epsilon. I think
ls thinks it's doing a DIRED output instead of a shell output. Now I need
to figure out why it thinks that. This wasn't happening in CentOS 7.
2015 Jun 22
2
OT: default password for HP printer
On 06/22/2015 02:51 PM, Fred Smith wrote:
> On Mon, Jun 22, 2015 at 02:30:00PM -0400, ken wrote:
>> On 06/22/2015 12:43 PM, Scott Robbins wrote:
>>> On Mon, Jun 22, 2015 at 11:31:34AM -0400, ken wrote:
>>>> For some reason the "tech support" people at Hewlett-Packard don't
>>>> know what the default password is to access their printer's
2013 Feb 28
4
Iteration through a list in R
Hello :)
I'm just starting out with R and would appreciate your help with a couple
of problems I am running into.
I have used Sys.glob to get a list of all filenames having a particular
file extension (in my case, *.txt)
I would now like to use this list in the following manner: I would like to
use each filename from the list and open that file into a tab separated
matrix and proceed.
How can
2011 Oct 06
1
Porting samba setup to backup server
I must set up a backup server for failover and have used tdbbackup to create backup files from the functioning primary server. I then copied the files to the backup server and used tdbbackup to restore all the databases, along with copying the smb.conf and other text files from /etc/samba. This does not seem to work and I was hoping someone could assist.
Primary server is RHEL 5.4 with Samba
2012 Oct 04
2
How to build a list with missing values? What is missing, anyway?
This is tangentially related to Hadley's question.
Suppose I'm building a function programmatically; I have assembled an
expression for the body and I know the names of the arguments it wants
to take.
Suppose I have some convenience function such that writing
make_function(alist(a=, b=), quote(a+b), environment())
is equivalent to writing
function(a,b) a+b
So how do I make the
2009 Jan 14
2
coercing a list into matrix
Dear list,
I have a list of number sequences. Each number sequence has different
numbers of elements. Is there a quick way (other than to iterate
through the entire list) way to coerce list to matrix with NAs filling
in the short sequences?
An example of what I mean is this:
A <- list(c(3,2,3),c(6,5))
I'd like to get A so that it is
3 2 3
6 5 NA
Best,
Ken
2004 Sep 14
3
Getting the argument list within a function
Is there a way of getting the argument list of a function from within
that function? For example, something like
f <- function(x, y = 3) {
fargs <- getFunctionArgList()
print(fargs) ## Should be `alist(x, y = 3)'
}
Thanks,
-roger
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})