Displaying 20 results from an estimated 10000 matches similar to: "Matrix to "indexed" vector"
2004 May 27
4
extract columns using their names
Hello,
Is there a way to extract multiple columns from a dataframe using their
names instead of their numbers?
Currently I use:
data2 <- data1[, c(1,3,9)]
And I am looking for something like
data2 <- data1[, c("XX","YY","ZZ")]
I use the same dataframe for many purposes, and I run codes that change
the order of the columns every time.
Many thanks,
Adrian
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
2008 Oct 22
2
Creating list from matrix
Hello everyone,
I have a matrix like :
mat <- matrix(rnorm(12*3), 3)
Now I want to break that matrix in 4 parts each of them are matrix of (3x3) and put those 4 matrices in a "list" object of length 4
Can anyone please tell me how to do that?
Get your new Email address!
Grab the Email name you've always wanted before someone else does!
[[alternative HTML
2004 Nov 09
2
do.call invoking a function with multiple arguments
Hi users,
I am not sure to understand the help page about do.call.
--
do.call(what, args)
args: a _list_ of arguments to the function call. The 'names'
attribute of 'args' gives the argument names.
--
If we take the following sample data:
> (tab=as.data.frame(table(factor(1:10))))
Var1 Freq
1 1 1
2 2 1
3 3 1
4 4 1
5 5
2004 Nov 18
5
Lexical Scoping: eval(expr,envir=)
Hi R-listers,
I am trying to better undertand what we would call "functional paradigm"
use of S/R to better map my programming activities in other languages.
This little function is aimed to create an object (at the end end, it would
have it's own class):
--
myObject =function(){
list(
a=1,
foo=function(b)
{
cat("b:",b)
2004 Nov 04
3
keep dimension of a sub matrix
Hi,
is there any way to keep a sub matrix dimension?
exemple :
i1<-1; i2<-1
j1<-2; j2<-3;
ret <-matrix(1,4,4)[i1:i2,j1:j2] ;
dim(ret) is NULL because the submatrix single col or single row is coerce to a vector automaticaly.
How can i bypass this cast : submatrix->vector ???????
Thank you.
---------------------------------
[[alternative HTML version
2004 Nov 25
4
Creating lists from matrices
Hello,
I am using R 1.9.1 on Windows 2000 SP4. I have the following problem:
Say I have a matrix,
>my.matrix
[,1] [,2] [,3]
[1,] "A" "B" "C"
[2,] "D" "E" "F"
[3,] "G" "H" "I"
I would like to apply an operation to this matrix which returns a list my.list
containing the
2010 Mar 18
2
how to take multiple subsets from a matrix
useR's
I have a matrix from which I want to take multiple subsets from, according
to a particular scheme I will now describe. The matrix below (mat) is 5x5,
and I want to take 9 subsets of it, each of dimension 3x3. The best way to
explain what the result should look like is with the following:
> dat <- c(3,6,1,9,12,9,2,10,6,5,3,13,1,4,8,9,4,6,10,11,2,7,3,5,10)
> miss <-
2007 Aug 22
1
plot in for loop with "i" indexed variables does not work
Hi there
Does anyone know, why this is not working?:
par(mfrow = c(5, 5))
for (i in 1:10){
plot(x=time, y=Var.i)
}
(x-variable is time
y-variable is Var out of matrix with columns Var.1 Var.2 Var.3 etc...)
even
for (i in 1:10){
plot(x=time, y=paste("Var", i, sep=".")
}
does not work
Thanks
marc
2005 Apr 04
1
Object item extraction
Hello
I am able to extract partial regression coefficients from a fitted model
object "model", i.e.
model <- lm(var.sel.gkm, weights = count.gkm, data = DATA)
summary(model)
write.table(model$coef, file = "C:/coef_CO_gkm.txt", row.names = TRUE,
col.names = TRUE)
I was wondering if anyone could advise me how to extract other object
items such as std. error, t-values
2010 Mar 09
3
Removing Zeros from matrix
Hi Everybody,
I have a matrix of about 45 columns. Some of the rows contain zeros. Using
>data1<-data[complete.cases(data),], I can remove the "NA" rows. But I am
unable to tackle that of zeros.
Can anybody give me an idea of how to remove rows containing zeros in a
matrix.
Thanks so much
Best
Ogbos
[[alternative HTML version deleted]]
2005 May 26
5
a more elegant approach to getting the majority level
Hi, I have a factor and I would like to find the most frequent level.
I think my current approach is a bit long winded and I was wondering if
there was a more elegant way to do it:
x <- factor(sample(1:0, 5,replace=TRUE))
levels(x)[ which( as.logical((table(x) == max(table(x)))) == TRUE ) ]
(The length of x will always be an odd number, so I wont get a tie in
max())
Thanks,
2006 Oct 16
2
Generate a random bistochastic matrix
Please, I would like to generate a random bistochastic matrix, that is a squared matrix of non-negative numbers with each row and each column sum to 1, for example :
.2 .3 .5
.6 .3 .1
.2 .4 .4
I don't know of to code this. Do you have any idea ?
Thanks
Florent Bresson
___________________________________________________________________________
Demandez ?
2010 Oct 15
4
split data with missing data condition
Dear all
I have data like this:
x y
[1,] 59.74889 3.1317081
[2,] 38.77629 1.7102589
[3,] NA 2.2312962
[4,] 32.35268 1.3889621
[5,] 74.01394 1.5361227
[6,] 34.82584 1.1665412
[7,] 42.72262 2.7870875
[8,] 70.54999 3.3917257
[9,] 59.37573 2.6763249
[10,] 68.87422 1.9697770
[11,] 19.00898 2.0584415
[12,] 60.27915 2.5365194
[13,] 50.76850
2009 Feb 12
3
get top 50 correlated item from a correlation matrix for each item
Hi,
I have a correlation matrix of about 3000 items, i.e., a 3000*3000
matrix. For each of the 3000 items, I want to get the top 50 items that
have the highest correlation with it (excluding itself) and generate a
data frame with 3 columns like ("ID", "ID2", "cor"), where ID is those
3000 items each repeat 50 times, and ID2 is the top 50 correlated items
with ID,
2005 Sep 09
3
how to do something like " subset(mat, ("col1">4 & "col2">4)) "
Dear all,
I have a problem with the "subset()" function. I spent all day yesterday
with a collegue to solve it and we did not find a satisfying solution (even
in the archived mails), so I ask for your help.
Let's say (for a simple example) a matrix mat:
R> mat
cola colb colc
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
My goal is to select the lines of the matrix on the basis of the
2005 Feb 15
2
special symobol / character
Hi all,
Is it possible to add a permil (or per mille) symbol to
an R plot (I couldn't find this symbol under demo(Hershey) or
the plotmath information).
In some ascii tables it is symbol no. 137.
cheers,
Matt.
[[alternative HTML version deleted]]
2008 Mar 02
3
elegant way to minus on each row of a matrix
How to do this in an elegant way formatrix/data frame/zoo?
mat=
1 2 3
4 5 6
7 8 9
vector=
1
2
3
result=
0 1 2
2 3 4
4 5 6
ie
1-1 2-1 3-1
4-2 5-2 6-2
7-3 8-3 9-3
Thanks in advance.
_________________________________________________________________
08
[[alternative HTML version deleted]]
2003 Dec 18
3
Summaries
Hello UseRs:
Excuses for my english.
I have a dataset with 65000 records and I'd like to make a summary where I
can view all the values (with the number of times that it repeats) that
there are each column of my dataset.
I tried with summary( ), str( ), but nothing gives me the result that I am
loking for.
Thank you very much.
2005 Aug 12
6
evaluating string variables
Hello!!!
I have a folder (C:/R/) with matrix files, named by number, i.e.
0.mat, 1.mat,...,1250.mat. In this case, they are 5x5 simetric
matrices. I would like to compute a property for each matrix and put
calculated values into a data frame for posterior ploting and
printing. Below there is an example for 7 matrices (0.mat..6.mat)
#define data frame
L <- data.frame(frame=numeric(7),