Sorkin, John wrote/hat geschrieben on/am 01.07.2024 17:54:
#I am trying to write code that will create a matrix with a variable number of
columns where the #number of columns is 1+Grps
#I can do this:
NSims <- 4
Grps <- 5
DiffMeans <- matrix(nrow=NSims,ncol=1+Grps)
DiffMeans
#I have a problem w
I think you should reconsider your goal. Matrices must have all elements of the
same type, and in this case you seem to be trying to mix a number of something
(integer) with mean values (double). This would normally be stored together in
a data frame or separately in a vector for counts and a ma
Às 16:54 de 01/07/2024, Sorkin, John escreveu:
#I am trying to write code that will create a matrix with a variable number of
columns where the #number of columns is 1+Grps
#I can do this:
NSims <- 4
Grps <- 5
DiffMeans <- matrix(nrow=NSims,ncol=1+Grps)
DiffMeans
#I have a problem when I try to
Às 16:54 de 01/07/2024, Sorkin, John escreveu:
#I am trying to write code that will create a matrix with a variable number of
columns where the #number of columns is 1+Grps
#I can do this:
NSims <- 4
Grps <- 5
DiffMeans <- matrix(nrow=NSims,ncol=1+Grps)
DiffMeans
#I have a problem when I try to
onday, July 1, 2024 11:54 AM
To: r-help@r-project.org (r-help@r-project.org)
Subject: [R] Create matrix with variable number of columns AND CREATE NAMES FOR
THE COLUMNS
[External Email]
#I am trying to write code that will create a matrix with a variable number of
columns where the #number of col
#I am trying to write code that will create a matrix with a variable number of
columns where the #number of columns is 1+Grps
#I can do this:
NSims <- 4
Grps <- 5
DiffMeans <- matrix(nrow=NSims,ncol=1+Grps)
DiffMeans
#I have a problem when I try to name the columns of the matrix. I want the
firs
rom: Jeff Newmiller
Sent: Monday, July 3, 2023 2:45 PM
To: Sorkin, John
Cc: r-help@r-project.org
Subject: Re: [R] Create matrix with column names wiht the same prefix
and that end in 1, 2
I really think you should read that help page. colnames() accesses
the second element of dimnames() di
aste("j","k",string)
zzz
# assign column names, j, k, xxx1, xxx2 to the matrix
# create column names, j, k, xxx1, xxx2.
dimnames(myvalues)<-list(NULL,c(zzz))
colnames(myvalues)<-zzz
From: Jeff Newmiller
Sent: Monday, July 3, 2023
umn names, j, k, xxx1, xxx2 to the matrix
# create column names, j, k, xxx1, xxx2.
dimnames(myvalues)<-list(NULL,c(zzz))
colnames(myvalues)<-zzz
From: Jeff Newmiller
Sent: Monday, July 3, 2023 2:45 PM
To: Sorkin, John
Cc: r-help@r-project.org
Subj
I really think you should read that help page. colnames() accesses the second
element of dimnames() directly.
On July 3, 2023 11:39:37 AM PDT, "Sorkin, John"
wrote:
>Jeff,
>Thank you for your reply.
>I should have said with dim names not column names. I want the Mateix to have
>dim names, no
Jeff,
Thank you for your reply.
I should have said with dim names not column names. I want the Mateix to have
dim names, no row names, dim names j, k, xxx1, xxx2.
John
John David Sorkin M.D., Ph.D.
Professor of Medicine
Chief, Biostatistics and Informatics
University of Maryland School of Medici
Às 19:00 de 03/07/2023, Sorkin, John escreveu:
I am trying to create an array, myvalues, having 2 rows and 4 columns, where the column
names are j,k,xxx1,xxx2. The code below fails, with the following error, "Error in
dimnames(myvalues) <- list(NULL, zzz) :
length of 'dimnames' [2] not equal
?colnames
On July 3, 2023 11:00:32 AM PDT, "Sorkin, John"
wrote:
>I am trying to create an array, myvalues, having 2 rows and 4 columns, where
>the column names are j,k,xxx1,xxx2. The code below fails, with the following
>error, "Error in dimnames(myvalues) <- list(NULL, zzz) :
> length of '
I am trying to create an array, myvalues, having 2 rows and 4 columns, where
the column names are j,k,xxx1,xxx2. The code below fails, with the following
error, "Error in dimnames(myvalues) <- list(NULL, zzz) :
length of 'dimnames' [2] not equal to array extent"
Please help me get the code t
On 01/06/2011 12:16 PM, Chris English wrote:
Dear R_Help:
The following gives me a matrix with integer values.
z= matrix(rep(10:1, each= 10), ncol= 10, byrow=TRUE)> str(z) int [1:10, 1:10]
10 9 8 7 6 5 4 3 2 1 ...
How do I specify that I want Float32 values instead.
You can't. R doesn't sup
On 2011-06-01 09:16, Chris English wrote:
Dear R_Help:
The following gives me a matrix with integer values.
z= matrix(rep(10:1, each= 10), ncol= 10, byrow=TRUE)> str(z) int [1:10, 1:10]
10 9 8 7 6 5 4 3 2 1 ...
How do I specify that I want Float32 values instead.
Thanks,Chris
Have you tried
Dear R_Help:
The following gives me a matrix with integer values.
z= matrix(rep(10:1, each= 10), ncol= 10, byrow=TRUE)> str(z) int [1:10, 1:10]
10 9 8 7 6 5 4 3 2 1 ...
How do I specify that I want Float32 values instead.
Thanks,Chris
Thanks a lot guys...all of your solution are useful, and good.
once again thanks.
--
View this message in context:
http://r.789695.n4.nabble.com/Create-Matrix-of-2-Dim-from-two-vectors-tp3031718p3031797.html
Sent from the R help mailing list archive at Nabble.com.
Hi:
If you want the literal character strings, this works:
x<-c(1, 2, 3)
> y<-c(4,5,6)
> outer(x, y, function(x, y) paste('(', x, ',', y, ')', sep = '') )
[,1][,2][,3]
[1,] "(1,4)" "(1,5)" "(1,6)"
[2,] "(2,4)" "(2,5)" "(2,6)"
[3,] "(3,4)" "(3,5)" "(3,6)"
However, I have the sense y
Hi,
First, create a MATRIX of the correct size:
xy <- matrix(nrow=3, ncol=3)
Then, in your for loop, you need to index each cell correctly, like this:
xy[i,j]
Finally, if you want to assign "1,4" to each cell, you need to paste
x[i] and y[j] together, like this:
xy[i,j]<-paste(x[i],y[j], sep=
Try
x1<-matrix(1,3,1)%x%x
y1<-y%x%matrix(1,3,1)
Z<-cbind(x1,y1)
And later you need to move towards list and matrix
On Mon, Nov 8, 2010 at 11:15 AM, abotaha wrote:
>
> Hello,
>
> I have two data.
>
> x<-c(1, 2, 3)
> y<-c(4,5,6)
>
> How do i create matrix of 3 by 3 from this two, such that
>
>
Hello,
I have two data.
x<-c(1, 2, 3)
y<-c(4,5,6)
How do i create matrix of 3 by 3 from this two, such that
(1,4) (1,5) (1,6)
(2,4) (2,5) (2,6)
(3,4) (3,5) (3,6)
I tried some thing like this:
xy <- as.data.frame(c(0,0,0), dim=c(3,3))
for(i in 1:3)
for(j in 1:3)
xy[i][j]<-c(x[i
On Feb 1, 2010, at 9:38 AM, Muhammad Rahiz wrote:
Hello all,
Thanks for all your replies.
Usually, when I make a post to the R-mailing list, I would keep on
trying to get the solution myself rather than waiting for one. At
times, I was able to derive my own solution. This would explain wh
Hello all,
Thanks for all your replies.
Usually, when I make a post to the R-mailing list, I would keep on
trying to get the solution myself rather than waiting for one. At times,
I was able to derive my own solution. This would explain why my solution
and that of Dennis's produces the same r
On Jan 29, 2010, at 1:07 PM, Muhammad Rahiz wrote:
OK, I've got this. The output prints what I want, but I'm not sure
if there will be problems in further analysis because the main idea
is to convert the data from list to matrix. I'm quite concerned with
how I define xx2.
xx <- unlist(
OK, I've got this. The output prints what I want, but I'm not sure if
there will be problems in further analysis because the main idea is to
convert the data from list to matrix. I'm quite concerned with how I
define xx2.
xx <- unlist(x) # Unlist from lapply + read.table
a <- seq(1,1
On Jan 29, 2010, at 12:43 PM, Muhammad Rahiz wrote:
Thanks David & Dennis,
I may have found something.
Given that the object xx is the product of unlist(x), to create a
2x2 matrix with subsets, I could do,
> y <- matrix(xx[c(1:4)], 2, 2).
This returns,
[,1] [,2]
[1,] -27.3 14.4
[2
Thanks David & Dennis,
I may have found something.
Given that the object xx is the product of unlist(x), to create a 2x2
matrix with subsets, I could do,
> y <- matrix(xx[c(1:4)], 2, 2).
This returns,
[,1] [,2]
[1,] -27.3 14.4
[2,] 29.0 -38.1
If I do,
> y2 <- matrix(xx[c(5:8)],2,2
On Jan 29, 2010, at 9:45 AM, Dennis Murphy wrote:
Hi:
The problem, I'm guessing, is that you need to assign each of the
matrices
to an object.
There's undoubtedly a slick apply family solution for this (which I
want to
see, BTW!),
I don't have a method that would assign names but you c
Hi:
The problem, I'm guessing, is that you need to assign each of the matrices
to an object.
There's undoubtedly a slick apply family solution for this (which I want to
see, BTW!),
but here's the brute force method using a loop:
nms <- paste('x', 1:32, sep = "")
for(i in seq_along(nms)) assign(nm
Hello all,
I'm trying to create a 2x2 matrix, 32 times after unlist() so that I can
convert the list to matrix. I've looked through the R archive but
couldn't find the answer. There is what I've done.
> f <- system("ls *.txt", intern=TRUE)
> x <- lapply(f, read.table)
> x
[[1]]
V1V2
on 06/19/2008 09:59 AM Gundala Viswanath wrote:
Hi,
I have the following dataset (simplified for example).
__DATA__
300.35 200.25 104.30
22.00 31.12 89.99
444.50 22.10 43.00
22.10 200.55 66.77
Now from that I wish to do the following:
1. Compute variance of each row
2. Pick top-2 row with hi
Dear Gundala,
Try this:
# Data set
DF=read.table(textConnection("300.35 200.25 104.30
22.00 31.12 89.99
444.50 22.10 43.00
22.10 200.55 66.77"),header=FALSE,sep="")
# Variances
VAR=apply(DF,1,var)
# Order
pos=order(VAR)
# Print VAR and pos
VAR
pos
# ordered VAR
VAR[pos]
# top-2 highest VAR
Hi,
I have the following dataset (simplified for example).
__DATA__
300.35 200.25 104.30
22.00 31.12 89.99
444.50 22.10 43.00
22.10 200.55 66.77
Now from that I wish to do the following:
1. Compute variance of each row
2. Pick top-2 row with highest variance
3. Store those selected rows for fu
It depends on how you have your data laid out. This
is clumsy but I think it will work. There should be
an easier way than a loop but I don't see it. People
with more experience in R will likely have much better
solutions.
In any case it sure beats Excel or any other
spreadsheet :)
chek - UNSW
Sent: Thu 20/03/2008 4:51 PM
To: r-help@r-project.org
Subject: [R] create matrix
Hi all,
I have a dataset consisting of 5 columns and over 5000 rows. Each row
gives information about an individual animal, including longevity, i.e.
at what age an animal died.
For the model I use I n
Since you did not provide a sample of your data, here is an example of
how to take a vector and create a matrix with 5 entries for each
value, with the extra ones having a zero in the second column:
> x <- sample(1:7, 20, T)
> table(x)
x
1 2 3 4 5 6 7
2 4 3 2 4 4 1
> # create a matrix with 5 rows
Hi all,
I have a dataset consisting of 5 columns and over 5000 rows. Each row
gives information about an individual animal, including longevity, i.e.
at what age an animal died.
For the model I use I need to create n rows for each animal, n being its
longevity, and a new column 'survival' with a
38 matches
Mail list logo