Displaying 20 results from an estimated 20000 matches similar to: "reverse order of matrix rows"
2009 Mar 11
3
Converting a dataframe to a matrix
If I have a dataframe which is organized like this:
name color likes?
1 sally red 0
2 sally blue 1
3 sally green 1
4 jake red 0
5 jake blue 1
6 jake green 1
7 tom red 1
8 tom blue 0
9 tom green 0
And I want to create a matrix in the form:
red blue green
sally 0 1 1
jake 0 1 1
tom 1 0 0
Are there any built-in
2005 Aug 29
2
reexpand a matrix after subsetting
Hi,
suppose I have a matrix (or dataframe)
as a result from subsetting.
mat <- matrix(1:20,ncol=2)
mat[c(3,6,9),] <- NA
cc <- complete.cases(mat)
sub <- mat[cc,,drop=FALSE]
sub <- sub * 2
#some caluculations with sub.
now I would like to expand sub somehow
so row 3,6, and 9 would be filled with
NAs but the rest should be in place again.
Is there a simple function for this?
2005 Jul 18
5
colnames
Hi,
I have a matrix with column names starting with a character in [0-9]. After some matrix operations (e.g. copy to another matrix), R seems to add a character 'X' in front of the column name. Is this a normal default behaviour of R? Why has it got this behaviour? Can it be changed? What would be the side effect?
Thank you.
Regards,
Gilbert
[[alternative HTML version deleted]]
2011 Nov 06
1
Deleting rows dataframe in R conditional to “if any of (a specific variable) is equal to”
Dear list,
I have been struggling for some time now with this code... I have this vector of unique ID "EID" of length 821 extracted from one of my dataframe (skate). It looks like this:
> head(skate$EID)
[1] "896-19" "895-8" "899-1" "899-5" "899-8" "895-7"
I would like to remove the complete rows in another dataframe
2011 Nov 06
1
Combining some duplicated rows & summing one of their column
Dear list,
I have this dataframe:
> names(events)
[1] "EID" "X" "Y" "trip" "tow" "catch" "effort" "depth"
[9] "season"
Where some of my unique ID "EID" appears more than once in 162 cases.
> length(events$EID)-length(unique(events$EID))
[1] 162
I would like to combined
2008 Aug 24
1
howto optimize operations between pairs of rows in a single matrix like cor and pairs
Hi,
I calculating the output of a function when applied to pairs of row from
a single matrix or dataframe similar to how cor() and pairs() work. This
is the code that I have been using:
pairwise.apply <- function(x, FUN, ...){
n <- nrow(x)
r <- rownames(x)
output <- matrix(NA, nc=n, nr=n, dimnames=list(r, r))
for(i in 1:n){
for(j
2006 Mar 17
3
Binning question (binning rows of a data.frame according to a variable)
Hi,
I have tuples of data in rows of a data.frame, each column is a variable
for the 'items' (one per row).
One of the variables is the 'size' of the item (row).
I would like to cut my data.frame into groups such that each group has
the same *total size*. So, assuming that we order by size, some groups
should have several small items while other groups have a few large
2011 Jul 01
1
Reverse legend label order in barplot
Hi list,
I've thus far not found a solution to my problem and hope someone can help.
I have a data matrix and wish to plot a stacked bar plot using barplot().
This is simple enough, but I have a problem with the legend labels being in
the reverse order from what I want. The default appears to have labels
ascending bottom-to-top reflecting bottom-to-top sub-bars, but I would like
the
2005 Mar 22
3
Newbie: Matrix indexing
Hi all,
I need to compute some "occurence matrix": given a zero matrix and a set
of paired indexes, I want to store the number of occurences of each paired
index in a matrix. The paired indexes are stores as an index matrix. I
prefere not to use loops for performances purpose.
Here follows a dummy example:
> occurence <- matrix(0, 2, 2); data
[,1] [,2]
[1,] 0 0
2013 Sep 02
3
Product of certain rows in a matrix
Hi,
You could try:
A<- matrix(unlist(read.table(text="
1 2 3
4 5 6
7 8 9
9 8 7
6 5 4
3 2 1
",sep="",header=FALSE)),ncol=3,byrow=FALSE,dimnames=NULL)
library(matrixStats)
?res1<-t(sapply(split(as.data.frame(A),as.numeric(gl(nrow(A),2,6))),colProds))
?res1
#? [,1] [,2] [,3]
#1??? 4?? 10?? 18
#2?? 63?? 64?? 63
#3?? 18?? 10??? 4
2005 Nov 11
0
Fwd: Re: conditional coloring of image labels
---------- Forwarded Message ----------
Subject: Re: [R] conditional coloring of image labels
Date: Friday 11 November 2005 1:04 pm
From: jim holtman <jholtman at gmail.com>
To: Jake Michaelson <jjmichael at cc.usu.edu>
Use 'mtext':
genes=cbind(ABC1=c(3,4,4,5,6,3), ABC2=c(4,3,4,7,7,8), ABC3=c(8,7,8,6,3,2))
###plot the image
image(1:nrow(genes), 1:ncol(genes), genes, axes =
2011 Jul 23
1
Achieving 'reverse-Vech' of a matrix
Let say i have a square matrix and applied the 'vech' operator to stack the lower triangular elements into a vector:
> Mat <- matrix(1:25, 5)
> Mat
? ? ?[,1] [,2] [,3] [,4] [,5]
[1,] ? ?1 ? ?6 ? 11 ? 16 ? 21
[2,] ? ?2 ? ?7 ? 12 ? 17 ? 22
[3,] ? ?3 ? ?8 ? 13 ? 18 ? 23
[4,] ? ?4 ? ?9 ? 14 ? 19 ? 24
[5,] ? ?5 ? 10 ? 15 ? 20 ? 25
> Mat[lower.tri(Mat)]
?[1] ?2 ?3 ?4 ?5 ?8 ?9 10 14
2005 Aug 03
5
make error: X11/Intrinsic.h: No such,,,
Hi all,
I'm trying to build R 2.1.1 on Ubuntu 5.04 i686-SMP. Configure goes well
with:
./configure --with-BLAS --with-readline=no
but once I run 'make', I get the following error:
In file included from devX11.c:64:
devX11.h:57:74: X11/Intrinsic.h: No such file or directory
Any ideas?
Thanks in advance,
Jake
2005 Aug 05
4
interpolation function
Hi,
I have a sparse matrix.I want to fill values into the entries whose value
is 0.The new generated values should come from the interpolation of the
values have existed.Does R provide such interpolation functions which
operate on Matrix, for example ,such a matrix below
0 0 0 0 2.3 0 0 0 0
0 0 3.1 0 0 0 0 1.4 0
0 0 0 0 0 0 0 0 0
1.1 0 0 0 0 0 0 0 0
0 0 0 4
2018 May 22
0
remove rows of a matrix by part of its row name
Hello,
Use grep to get the row indices and then subset with a *negative* index
to remove those rows.
rn <- scan(what = character(), text = "
70/556
71.1/280
72.1/556
72.1/343
73.1/390
73.1/556
")
mat <- matrix(rnorm(6*6), nrow = 6)
row.names(mat) <- rn
inx <- grep("73\\.", row.names(mat))
new_mat <- mat[-inx, ]
new_mat
Hope this helps,
Rui Barradas
On
2018 May 22
4
remove rows of a matrix by part of its row name
Dear R-experts,
How can I remove a certain feature or observation by a part of its name. To be clear, I have a matrix with 766 observations as a rows. The row names are like this
70/556
71.1/280
72.1/556
72.1/343
73.1/390
73.1/556
Now I would like to remove all the rows that contain the text 73.1
Any ideas or suggestion please ?
Regards
**********************
Ahmed Serag
Analytical
2010 Nov 29
1
Extracting selected rows from a matrix
Hi,
I have matrix of 104 columns and 30000 rows (Each Row has rowname).
I have 13 different list of selected rownames (character) say 1000 each. Now I want to extract the all the columns according to the rownames in each the list.
How can I do that in R ?
1 ) For a single list
2) For all the 13 list at a time
Regards,
Pankaj Barah
Department of Biology,
Norwegian University of
2000 Aug 21
4
Excluding rows from a matrix
Hi
I have a matrix (4 x 950) and I want to remove 3 rows, where the values
from the first column are 713, 714 and 715. I can select the rows, one
by one, with
mat[mat$first==713,]
mat[mat$first==714,]
...
but I'm unable to (i) select the 3 rows at once, (ii) select the matrix
excluding those rows.
How can I do it ?
Thanks
EJ
2008 Feb 20
2
intersecting rows of a matrix
useR's,
First, I would like to say thanks to John Fox for providing this segment of
code to perform intersection for multiple sets:
intersection <- function(x, y, ...){
if (missing(...)) intersect(x, y)
else intersect(x, intersection(y, ...))
}
I want to execute this function on the rows of a matrix I have:
Ik.mat.test <- matrix(c(2,3,6,1,2,6,6,1,2),byrow=T,nrow=3)
> Ik.mat.test
2006 Feb 21
1
call row names
Hi R users.
I have a table like that:
table
var
A1
A2
A3
v1
41203
3.69
2.31
v2
20577
4.51
8.60
v3
20625
2.87
3.50
v4
6115
8.92
2.97
v5
3160
1.49
2.21
v6
2954
2.62
5.98
v7
4731
1.83
7.53
v8
2435
7.68
3.50
v9
2296
3.03
4.84
v10
6153
1.06
4.28
v11
3157
1.07
1.15
v12
2996
1.06
1.01
v13
6084
2.65
2.63
v14
3115
2.42