Sent: Monday, September 10, 2018 8:33 PM
To: r-help@r-project.org
Subject: Re: [R] For loop with multiple iteration indexes
Thank you everyone. After thinking about each response, I realized a fairly
simple solution is available (obviously, other suggested approaches work as
well):
stopifnot(leng
Thank you everyone. After thinking about each response, I realized a fairly
simple solution is available (obviously, other suggested approaches work as
well):
stopifnot(length(x) == length(y); stopifnot(length(x) > 0)
r <- list()
for (i in 1:length(x) ) {
r[[i]] <- cor(x = dat[, x[i] ], y = dat
I have a sense of deja vu:
https://www.mail-archive.com/r-help@r-project.org/msg250494.html
There is some good advice there.
> On Sep 9, 2018, at 3:49 PM, David Disabato wrote:
>
> Hi R-help,
>
> I am trying to create a for loop with multiple iteration indexes. I don't
> want to use two diffe
Hi,
this simple example is very similarly, and it works in R:
r <- list()
n <- 0
x <- c("a","b","c")#x,y: Data from a dataframe
y <- c("A","B","C")
for (k in 1:3) {
n <- n+1
r[[n]] <- paste0(x[k],y[k])#or any other function using x[k] and y[k] as
arguments
}
print(r)
Is it this what you
Hi David,
If you mean that you have two data frames named x and y and want the
correlations between the columns that would be on the diagonal of a
correlation matrix:
r<-list()
for(i in 1:n) r[[i]]<-cor(x[,i],y[,i])
If I'm wrong, let me know.
Jim
On Mon, Sep 10, 2018 at 3:06 PM David Disabato
5 matches
Mail list logo