similar to: Creating a Matrix from a vector with some conditions

Displaying 20 results from an estimated 10000 matches similar to: "Creating a Matrix from a vector with some conditions"

2011 Jan 06
2
Help with IF operator
Hi, I am with a problem on how to do a comparison of values. My script is as follows: repeat{ cat("How many teams to use? (to end write 0) ") nro<-scan(n=1) if(nro==0)break cat("write the", nro, "teams names \n") teams<-readLines(n=nro) if (teams[1]==teams[2)next else print(teams) } On this example I only compare teams 1 name with teams 2 name, and if they
2011 Jan 04
5
Help with "For" instruction
Hi, I am having a problem in doing something similar to this example: Suppose I have this vector a, and from it I wish to create 5 other vector each one with less one value than what object a has So I have "a" a<-c(1,2,3,4,5) and I want a1 that shoud have (2,3,4,5) a2 that should have (1,3,4,5) a3 that should have (1,2,4,5) a4 that should have (1,2,3,5) a5 that should have
2011 Jan 18
4
Relative frequency on a character vector
Hi, I have this character vector: A<-c("Tell me how many different letter this vector has?") Is there a way with R that it can let me know how many different letters I have on this vector? If I use nchar(A) que gives me the number 50. With this function he is counting all the letters present and also spaces between the words. Can we also not count the spaces between words? Then
2011 Feb 01
3
sum the values in a vector as a complete number
Hi I am trying to create a function that is able to calculate this sum: a<-c(2,3,5) b<-(8,7) with "a" meaning 235 and "b" 87. So the result of this sum would be 235 + 87 = 322. I've searched a function like strsplit but that worked for integers and in reverse - not spliting but combining. Can you give me a hand on this please? thanks AD -- View this message in
2011 Jan 01
3
How to make this script ask again
Hi, as an example I have made this script to give the user the answer if a number is odd or even: { cat("Please, enter a number (Zero ends)") n<-scan(n=1) if(n==0)break i<-("The number is odd") p<-("The number is even") if (n%%2==0) p else i } If you run this script it will only work once, I mean, after it gives you the answer is won't ask for
2010 Dec 31
1
Silhouette function problem
Hi, I am using code below to get a plot that will show me on the X axis the number of clusters and on the Y axis the cluster average widths. However I am getting this error: Error in summary(silhouette(cutree(d, x), dist(iris[, -5])))$si.summary : $ operator is invalid for atomic vectors the code I am using is: avgs<-sapply(1:20,function(x) summary(silhouette(cutree(d,x),
2011 Feb 10
3
Permuting rows of a matrix
Hi, I need to permute the rows of a matrix, where each row is independently rearranged. A simple solution is this: shuffled <- datamatrix <- matrix(1:24, ncol = 4) for (i in 1:nrow(datamatrix)) { shuffled[i, ] <- sample(datamatrix[i, ]) } > datamatrix [,1] [,2] [,3] [,4] [1,] 1 7 13 19 [2,] 2 8 14 20 [3,] 3 9 15 21 [4,] 4 10 16 22 [5,]
2005 Mar 09
2
Structural equation models with R
Hello useRs, I`m running structural equation models with R, but for one of my models the below error message apears. I`m trying to change startvalues but without success. The manual for sem package did not help me. Does anyone knows how to change startvalues for iteration in sem package? Or it can be another problem with the model? Error in startvalues(S, ram, debug = debug, tol = start.tol)
2012 Feb 17
2
(subscript) logical subscript too long in using apply
Dear ALL I have this function in R: func_LN <- function(data){ med_ge <- matrix(c(rep(NA,nrow(data)*ncol(data))), nrow = nrow(data), ncol=ncol(data), byrow=TRUE) T <- matrix(c(rep(NA,length(n)*ncol(data))), nrow = length(n), ncol=ncol(data), byrow=TRUE) Tdiff<- matrix(c(rep(NA,length(n)*ncol(data))), nrow = length(n), ncol=ncol(data), byrow=TRUE) T1<- c(rep(NA,ncol(data)))
2011 Jan 10
1
replace values in array with means of certain values in array
Een ingesloten tekst met niet-gespecificeerde tekenset is gescrubt ... Naam: niet beschikbaar URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110110/596768d9/attachment.pl>
2011 Feb 02
2
matrix and a function - apply function
Hi I have this function and this matrix: function(x,y) x+y/x m<-matrix(c(1,2,4,2,10,8),3,2) > m [,1] [,2] [1,] 1 2 [2,] 2 10 [3,] 4 8 each row represent a point (x,y) in a chart and I want via my fucntion to calculate the image in order to get this results: for point (1,2) I would get 1+2/1 = 3 for point (2,10) I would get 2+10/2 = 7 for point (4,8) I would get
2012 Apr 25
2
comparison of bivariate normal distributions
sorry for cross-posting Dear all, I have tow (several) bivariate distributions with a known mean and variance-covariance structure (hence a known density function) that I would like to compare in order to get an intersect that tells me something about "how different" these distributions are (as t-statistics for univariate distributions). In order to visualize what I mean hear a little
2012 Mar 14
3
Creating 250 submatrices from a large single matrix with 2500 variables using loops
Dear all, I have a large matrix with about 2500 variables, and 100 rows. I would like to calculate the means of the every 10 variables starting from 1:2500 and saving the results as a vector or matrix. How can I do that? Alternatively, How can I create 250 subset matrices in the order of variables 1:2500 in groups of 10 from the single matrix which had initially 2500 variables ? I guess I have
2008 Sep 21
1
Calculating interval for conditional/unconditional correlation matrix
Hi there, Could anyone please help me to understand what should be done in order not to get this error message: Error: evaluation nested too deeply: infinite recursion / options(expressions=)? Here is my code: determinant<- function(x){det(matrix(c(1.0,0.2,0.5,0.8,0.2,1.0,0.5,0.6,0.5,0.5,0.5,1.0,x,0.8,0.6,x,1.0),ncol=4,byrow=T))} matrix<-
2011 Mar 29
4
Simple but elusive - expand back from counts
Dear R-users, This should be simple but still eludes me: Given the following tmp<-as.data.frame(matrix(c(44, 10, "abc", 1, 44, 10, "def", 1, 44, 12, "abc", 2), 3, 4, byrow=T)) I want to expand the data to the following form: V1 V2 V3 V4 1 44 10 abc 1 2 44 10 def 1 3 44 12 abc 1 4 44 12 abc 1 The last row of the original df was duplicated the row by the
2012 Jun 15
3
moving from loops to apply
Dear subscribers, I have made a simulation using loops rather than apply, simply because the loop function seems more natural to me. However, the current simulation takes forever and I have decided - finally - to learn how to use apply, but - as many other people before me - I am having a hard time changing habits. My current problem is: My current code for the loop is: distances <-
2010 Nov 19
5
how to apply sample function to each row of a data frame?
this is a simple question, but I wasn't able to figure it out myself. here is the data frame: M P Q 1 2 3 4 5 6 7 8 9 M, P, Q each represent a variable I want to draw 2 random sample from each row separately to create a new data frame. how can I do it? thanks!! -- View this message in context:
2012 Apr 24
2
Basic matrix manipulation problem
Hello, this forum was very helpful yesterday with a simple question I had on working with tables. What function will I need to use to do the following. Move matrix a: A B C D x 1 2 3 4 y 5 6 7 8 to the mean of B&C and C&D: BC CD x 2.5 3.5 y 6.5 7.5 and then to the mean of B&CB, C&BC, C&CD, and D&CD: AAB BAB
2005 Jul 12
3
elegant matrix creation
Hi I want to write a little function that takes a vector of arbitrary length "n" and returns a matrix of size n+1 by n+1. I can't easily describe it, but the following function that works for n=3 should convey what I'm trying to do: f <- function(x){ matrix(c( 1 , 0 , 0 , 0, x[1] , 1 , 0 , 0, x[1]*x[2] , x[2] , 1 , 0,
2001 Sep 10
3
inter tick distance
R colleagues, I am stumped. I would like the inter-tick distances to be the same on the x and y axes but cannot determine how to do so when the lower half of the y axis is not printed. Thanks for any and all suggestions. (btw, setting par(pty="s") does not solve my problem) Niels Waller M<-matrix(c(2,1, -1,3),2,2,byrow=TRUE)