similar to: Split a vector(list) into 3 list

Displaying 20 results from an estimated 60000 matches similar to: "Split a vector(list) into 3 list"

2013 Oct 11
3
matrix values linked to vector index
Hi, In the example you showed: m1<- matrix(0,length(vec),max(vec)) 1*!upper.tri(m1) #or ?m1[!upper.tri(m1)] <-? rep(rep(1,length(vec)),vec) #But, in a case like below, perhaps: vec1<- c(3,4,5) ?m2<- matrix(0,length(vec1),max(vec1)) ?indx <- cbind(rep(seq_along(vec1),vec1),unlist(tapply(vec1,list(vec1),FUN=seq),use.names=FALSE)) m2[indx]<- 1 ?m2 #???? [,1] [,2] [,3] [,4] [,5]
2008 Nov 24
8
matching matrix columns to a vector
I need help with (hopefully) just one more thing. I have been fussing with this for quite some time and have decided just to give up and ask! I want to match a column in a matrix to a vector. I found a "which" command that I thought would be helpful as it does the following: > g=c(1,5,3,2,7) > which(g==5) [1] 2 As the above gave which placement in the g vector corresponded to
2006 Aug 22
2
listing a sequence of vectors in a matrix
Hi, I'm having trouble applying the matrix function. I'd like to be able to create a matrix of vectors filled in by rows, which are not all the same length, and so I need it to fill in NAs where applicable. It's easiest to explain with a simple example: Suppose vec = c(3,4,5). How can I form a matrix of the vectors 1:vec[j] for j=1:3? i.e. 1 2 3 NA NA 1 2 3 4
2010 Aug 17
4
replacing values in a vector
Dear helpRs Does anyone have an elegant way of doing the following: For a given numeric vector, e.g. vec <- c(3,2,6,4,7) Create a series of vectors where all but 1 of the values are replaced by 0's, e.g. vec.a <- c(3,0,0,0,0) vec.b <- c(0,2,0,0,0) vec.c <- c(0,0,6,0,0) vec.d <- c(0,0,0,4,0) vec.e <- c(0,0,0,0,7) I have looked at `replace', but can't think of a
2013 Mar 08
2
Unexpected behaviour of apply()
Hello everyone, Considering the following code sample : ---- indexes <- function(vec) { vec <- which(vec==TRUE) return(vec) } mat <- matrix(FALSE, nrow=10, ncol=10) mat[1,3] <- mat[3,1] <- TRUE ---- Issuing apply(mat, 1, indexes) returns a 10-cell list, as expected. Now if I do: ---- mat[1,3] <- mat[3,1] <- FALSE apply(mat, 1, indexes) ---- I would expect a
2010 Dec 22
3
How to integrate a function with additional argument being a vector or matrix?
Dear expeRts, I somehow don't see why the following does not work: integrand <- function(x, vec, mat, val) 1 # dummy return value A <- matrix(runif(16), ncol = 4) u <- c(0.4, 0.1, 0.2, 0.3) integrand(0.3, u, A, 4) integrate(integrand, lower = 0, upper = 1, vec = u, mat = A, val = 4) I would like to integrate a function ("integrand") which gets an "x" value (the
2013 Feb 03
2
Compare each element of a list to a vector
Hello R-helpers, I have a vector x<-c(1,2,3) and a list that contains vectors datalist<-list(c(1,2,3),c(2,3,4),c(3,4,5),c(4,5,6)) and I would like to identify those list elements that are identical to x. I tried > datalist %in% x [1] FALSE FALSE FALSE FALSE but I am obviously using %in% incorrectly. I also tried messing around with lapply but I can't figure out how to specify
2011 Oct 03
2
Parsing variable-length delimited strings into a matrix
I'm struggling to find a way of parsing a vector of data in this sort of form: A,B,C B,B A,AA,C A,B,BB,BBB,B,B into a matrix (or data frame). The catch is that I don't know a priori how many entries there will be in each element, nor how many characters there will be. strsplit(vec,",") gets me a list, but I can't find a way of turning the list into a matrix. unlistlst)
2010 Jan 29
2
evaluating expressions with sub expressions
Hallo I'm having trouble figuring out how to evaluate an expression when one of the variables in the expression is defined separately as a sub expression. Here's a simplified example mat <- expression(0, f1*s1*g1) # vector of formulae g1 <- expression(1/Tm) # expansion of the definition of g1 vals <- data.frame(f1=1, s1=.5, Tm=2) # one set of possible values for
2006 Oct 04
2
convert vector to matrix
Hi All, I have vector containing 10 elements(odservations). I need to put this into a matrix, where the matrix should contain only one column. I need this to be done using the cbind command because in the final table I should have a column of attributes( from adifferent vector) and a column of vectors from the matrix above Please suggest me how this can be done Thanks and
2010 Jun 15
2
Integration problem: error in invoking an outside function
Dear all, Currently I am trying to integrate a function which depends on four variables, two of which are given, one is given in the integrate function, so there is one variable to integrate on. The code is as follows: Pmatrix = function(th) { P = matrix(nrow=6, ncol=6, data=0) P[1,1] = P[2,1]=P[3,2]=P[4,3]=P[5,4]=P[6,5]= exp(-th) P[,6] = 1-exp(-th) return(P)} lim.verd =
2011 Jan 11
1
how to coerce part of each column of a matrix to a vector and merge them
Hello Suppose I have a matrix mat=(1:16,2) [,1] [,2] [,3] [,4] [1,] 1 5 9 13 [2,] 2 6 10 14 [3,] 3 7 11 15 [4,] 4 8 12 16 there is a vector end=c(2,3,1,3) #coerce the 1st 2 numbers of the 1st column to a vector [1] 1 2 #coerce the 1st 3 numbers of the 2nd column and append it to the previous vector [1] 1 2 5 6 7 #coerce the 1st number of
2012 Jun 15
2
strings concatenation and organization (fast)
Hello, What is the fastest way to do this? I has to be done quite a few times. Basically I have sets of 3 numbers (as characters) and sets of 3 dashes and I have to store them in named columns. The order of the sets and the column name they fall under is important. The actual numbers and the pattern/order of the sets should be considered random/unpredictable. Sample data: vec =
2008 Oct 23
15
VEC Operator in R
Can anyone please tell whether there is any R function to act as "VEC" and "VECH" operator on Matrix? Yes of course, I can write a user-defined-function for that or else, I can put dim(mat) <- NULL. However I am looking for some R function. Your help will be highly appreciated. Regards, -- View this message in context:
2006 Aug 21
2
polychor error
Hi. Does anyone know whether the following error is a result of a bug or a feature? I can eliminate the error by making ML=F, but I would like to see the values of the cut-points and their variance. tmp.vec<-c(0, 0, 0 , 0 ,0 , 1, 0, 2, 0 , 0, 5 ,5 ,3 ,1, 0 , 1, 5, 10, 27, 20, 9, 0, 1, 1, 12, 29, 57, 34, 0, 0, 1, 2, 11, 31, 32) tmp.mat<-matrix(tmp.vec, nrow=7)
2011 Feb 11
3
How can we make a vector call a function element-wise efficiently?
Hello I have a time-comsuming program which need to simplify, I have tested the annotated program as follow: > #define function which will be call > calsta <- function(c, n=100000) + { + i <- seq(from=0, length=c) + logx <- lchoose(NT-n, CT-i) + lchoose(n, i) + logmax <- max(logx) + logmax + log(sum(exp(logx - logmax))) + } > CT=6000 #assignment to CT >
2008 May 21
1
split character string in matrix into character vector and numeric vector
Hello, I've got a matrix consisting of one column with n rows. Each field in the matrix is filled with a character vector. I would like to convert this matrix into a character vector containing the B03_MAH-type entries from the beginning of each row and a data.frame that contains the numeric data, but I am stuck. I have tried to use textConnection with sep = " " but since
2007 Dec 20
3
Efficient way to find consecutive integers in vector?
Hi all, Does anybody have a magic trick handy to isolate directly consecutive integers from something like this: c(1,2,3,4,7,8,9,10,12,13) The result should be, that groups 1-4, 7-10 and 12-13 are consecutive integers ... Thanks for any hints, Joh
2010 Nov 17
3
translate vector of numbers to indicies of 0/1 matrix
Hello All, Searched around, haven't found a decent solution. I'd like to translate a vector of numbers to a matrix (or to a list of vectors) such that the vector values would serve as indicies of the 1's in an otherwise-zero-filled matrix (or list of vectors). For example: > a = c(1,3,3,4) # perform operation [,1] [,2] [,3] [,4] [1,] 1 0 0 0 [2,] 0 0 1
2006 Apr 04
1
Indexing a vector by a list of vectors
Hello R-help - I have vec <- c("string1", "string2", "string3") ind <- list(c(1,2),c(1,2,3)) I want "vec" indexed by each vector in the list "ind". The first element of the list I want would be vec[c(1,2)], the second element would be vec[c(1,2,3)], like the following. [[1]] [1] "string1" "string2" [[2]] [1]