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() directly.
;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 2:45 PM
To
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
Subject: Re: [
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
À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
?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
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
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
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
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)
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 yaseen0...@gmail.com 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
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=,)
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 you want to use the
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.
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
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
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
1
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))
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
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 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,]
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 -
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 -
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
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
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 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
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 of
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 need to create n rows for each
31 matches
Mail list logo