similar to: repeated vector in matrix

Displaying 20 results from an estimated 20000 matches similar to: "repeated vector in matrix"

2004 Oct 20
2
Odd behaviour with scale()
Moi! A student here has been getting a bit irritated with some side effects of scale() (OS is Windows XP, the behaviour occurs in R 2.0.0, but not 1.7.1). The problem is that she scales a variable in a data frame, then does a regression, and tries to get some predictions for some new data. However, at this point she gets an error (see the example below). This seems to be because the
2007 Nov 22
1
Matrix of dummies from a vector
Hallo >From a variable "x" that defines, say, four classes, I would like to define the matrix "mat" of dummy variables indicating the classes, i.e. x <- c(1,1,1,1,2,2,2,3,3,3,4,4) mat <- matrix(c(1,0,0,0, 1,0,0,0, 1,0,0,0, 1,0,0,0, 0,1,0,0, 0,1,0,0, 0,1,0,0, 0,0,1,0, 0,0,1,0, 0,0,1,0, 0,0,0,1, 0,0,0,1), ncol=4, byrow=T) Thank you for your help, Serguei
2005 Jan 05
4
output from table() in matrix form
Hi How do I get the output from table() in matrix form? If I have R> table(c(1,1,1,1,2,20)) 1 2 20 4 1 1 I want [,1] [,2] [,3] [1,] 1 2 20 [2,] 4 1 1 The problem is that names(table) is a vector of characters and I need the numeric values. I am using R> rbind(as.integer(names(x)),x) I thought tabulate() might be better as it takes an
2005 Jun 13
3
extracting components of a list
Hi how do I extract those components of a list that satisfy a certain requirement? If jj <- list(list(a=1,b=4:7),list(a=5,b=3:6),list(a=10,b=4:5)) I want just the components of jj that have b[1] ==4 which in this case would be the first and third of jj, viz list (jj[[1]],jj[[3]]). How to do this efficiently? My only idea was to loop through jj, and set unwanted components to NULL,
2006 Sep 13
3
functions and strings
Hi If string <- "xyz" f <- function(x){1 + sin(cos(x)) + exp(x^2)} How do I manipulate "string" and f() to give the string "1 + sin(cos(xyz)) + exp(xyz^2)" ? -- Robin Hankin Uncertainty Analyst National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743
2005 Feb 25
3
restoring vector v from v[-i]
Hi I have a little function that takes a vector v and an integer i. I want to manipulate v[-i] (to give v.new, say) and then put (unmanipulated) v[i] back into the appropriate place. For example, f <- function(v,i){ v.new <- v[-i]+10 return(c(v.new[1:(i-1)],v[i],v.new[i:length(v.new)])) } (my example is adding 10 to v[-i], but the real version is the solution of a complicated
2006 Sep 06
1
Covariance/Correlation matrix for repeated measures data frame
All, I have a repeated measures data frame and was wondering if the covariance matrix can be calculated via some created indexing or built-in R function. Specifically, say there are 3 variables, where potassium concentration is measured 6 times on each patient. Patient number (discrete) Time (1 to 6, discrete) Potassium (continuous variable) I want the covariance/correlation matrix for the
2006 Feb 22
3
elements that appear only once
Hi. I have a factor and I want to extract just those elements that appear exactly once. How to do this? Toy example follows. > a <- as.factor(c(rep("oak",5) ,rep("ash",1),rep("elm",1),rep ("beech",4))) > a [1] oak oak oak oak oak ash elm beech beech beech beech Levels: ash beech elm oak > table(a) a ash beech elm oak
2007 Mar 19
3
character to numeric conversion
Hi. Is there a straightforward way to convert a character string containing comma-delimited numbers to a numeric vector? In my application, I use system(executable.string, intern=TRUE) which returns a string like "[0.E-38, 2.096751179214927596171268230, 3.678944959657480671183123052, 4.976528845643001020345216157, 6.072390165503099343887569007, 7.007958550337542210168866070,
2006 Nov 17
2
do.call("+", ...)
Hi How do I make do.call() take "+" as a function for a list of more than two elements? Toy problem follows: f <- function(i){matrix((1:6)^i,2,3)} # Thus f() returns a matrix of size 2x3; I want to add a whole bunch of such matrices, # as in f(1) + f(2) + f(3) + f(4) # But: > do.call("+",sapply(1:4,f,simplify=FALSE)) Error in do.call("+",
2008 Jun 11
4
Matrix transformation problem
ng, I have a matrix (x) with binary content. Each row of the matrix holds exactly one 1, and the rest of the row is zeros. The thing is that I need to 'collapse' the matrix to one column where each row holds the original column index of the 1's (y). Sometimes, the matrix is quite large, so I have a perfomance problem. x <- matrix(c(1,0,0, 0,0,1, 0,1,0, 0,0,1, 0,1,0,
2004 Jun 11
4
rownames of single row matrices
Hi I want to extract rows of a matrix, and preserve rownames even if only one row is selected. Toy example: R> a <- matrix(1:9,3,3) R> rownames(a) <- letters[1:3] R> colnames(a) <- LETTERS[1:3] R> a A B C a 1 4 7 b 2 5 8 c 3 6 9 Extract the first two rows: R> wanted <- 1:2 R> a[wanted,] A B C a 1 4 7 b 2 5 8 rownames come through fine. Now extract just
2007 Feb 13
4
Generating MVN Data
Dear All I want to generate multivariate normal data in R for a given covariance matrix, i.e. my generated data must have the given covariance matrix. I know the rmvnorm command is to be used but may be I am failing to properly assign the covariance matrix. Any help will be greatly appreciated thanks. M. R. Ahmad
2004 Sep 08
3
do.call("[", ...) question
Hi again everyone I have an arbitrarily dimensional array "a" and a list "jj" of length length(dim(a)). The elements of jj are vectors of indexes. How do I use do.call() to extract a[ jj[[1]], jj[[2]], jj[[3]], ...] ? Toy example follows: a <- matrix(1:30,5,6) jj <- list(5:1,6:1) I want the following a[ jj[[1]],jj[[2]] ] How do I do this? OBAttempts:
2006 Apr 06
3
convert a data frame to matrix - changed column name
I have a question, which very easy to solve, but I can't find a solution. I want to convert a data frame to matrix. Here my toy example: > L3 <- c(1:3) > L10 <- c(1:6) > d <- data.frame(cbind(x=c(10,20), y=L10), fac=sample(L3, + 6, repl=TRUE)) > d x y fac 1 10 1 1 2 20 2 1 3 10 3 1 4 20 4 3 5 10 5 2 6 20 6 2 > is.data.frame(d) [1] TRUE > sapply(d,
2005 May 06
4
how to get such a subset of a matrix?
Hi everybody, Maybe this question is quite simple but i just don't know how to make it. I have a matrix a somewhat like this one but bigger: > a f g h i j k a NA NA 11 16 21 26 b NA NA 12 17 22 27 c NA 8 13 18 23 28 d NA 9 14 19 24 29 e NA 10 15 20 25 30 And i want to get the rows which at most have 2 Na. Thanks in advance. Shi Jiantao [[alternative HTML version deleted]]
2007 Feb 01
2
Index mapping on arrays
Dear R-community, I have some trouble with index mappings for arrays. If, for example, I have the array R> A <- array(1:9, c(3,3,2)) and two index mappings both of same size R> x <- c(2, 3) R> y <- c(1, 2) Now I want to access the elements (A[1, x[i], y[i]])_i of A, i.e. A[1, x[1], y[1]] = A[1, 2, 1] and A[1, x[2], y[2]] = A[1, 3, 2]. If I use R> A[1, x, y] I would get
2008 Feb 26
1
predict.rpart question
Dear All, I have a question regarding predict.rpart. I use rpart to build classification and regression trees and I deal with data with relatively large number of input variables (predictors). For example, I build an rpart model like this rpartModel <- rpart(Y ~ X, method="class", minsplit =1, minbucket=nMinBucket,cp=nCp); and get predictors used in building the model like
2012 Mar 06
1
PLS Error message
Hi, I work with hyperspectral remote sensing data and I try to built a pls model with this data. I already built the model but if I try to calculate the RMSEP and R2 with a test data set I get the following error message: Error: variable 'subX' was fitted with type "nmatrix.501" but type "nmatrix.73" was supplied The problem is that I don't get the message for
2005 Jun 24
3
Counterpart for Matlab's 'feval'?
Hi! I've just begun writing a program that searches for the minimum of a function with golden section search. In order to do this in a nice way I need a function that takes a function name and an argument and returns the function value for that argument, i .e just like Matlab's 'feval'. Is there any? Thanks before hand! Best regards, Fredrik Thuring, Codan Insurance A/S