similar to: Match numeric vector against rows in a matrix?

Displaying 20 results from an estimated 10000 matches similar to: "Match numeric vector against rows in a matrix?"

2011 Jan 05
3
How to 'explode' a matrix
Hi everyone, I'm looking for a way to 'explode' a matrix like this: > matrix(1:4,2,2) [,1] [,2] [1,] 1 3 [2,] 2 4 into a matrix like this: > matrix(c(1,1,2,2,1,1,2,2,3,3,4,4,3,3,4,4),4,4) [,1] [,2] [,3] [,4] [1,] 1 1 3 3 [2,] 1 1 3 3 [3,] 2 2 4 4 [4,] 2 2 4 4 My current kludge is this:
2008 Dec 11
3
generate combination multiset (set with repetition)
Hi, This has been asked before but not sufficiently answered from what I could find. How do you create combinations with repetitions (multisets) in R? If I have > set <- array(1:3) And I want to choose all combinations of picking 2 numbers, I want to get a print out like [,1] [,2] [1,] 1 1 [2,] 1 2 [3,] 1 3 [4,] 2 2 [5,] 2 3 [6,] 3 3 subsets(set,
2011 Mar 21
1
Basic Looping Trouble
Hi all, Forgive me for this basic question. I've been doing some research and haven't been able to figure out how to best do this yet. I have 75 variables defined as vector time series. I am trying to create a script to automate calculations on each of these variables, but I wasn't sure how to go about calling variables in a script. I am hoping to write a loop that calls a list of
2007 Dec 29
1
COMPAR.GEE error with logistic model
Hello, I am trying to run the APE program COMPAR.GEE with a model containing a categorical response variable and a mixture of continuous and categorical independent variables. The model runs when I have categorical (binary) response and two continuous independent variables (VAR1 and VAR2), but when I include a categorical (binary) independent variable (VAR3), I receive the following output with
2011 Mar 17
2
Counting
I have a matrix say: 23 1 12 12 0 0 0 1 0 1 0 2 23 2 I want to count of number of distinct rows and the number of disinct element in the second column and put these counts in a column. SO at the end of the day I should have: c(1, 1, 1, 2, 2, 1, 1) for the distinct rows and c(1, 1, 1, 2, 2, 2, 2) for the counts of how many times the elements in the second column exists. Any help is
2012 Apr 04
2
cluster analysis with pairwise data
Hello, I want to do a cluster analysis with my data. The problem is, that the variables dont't consist of single value but the entries are pairs of values. That lokks like this: Variable 1: Variable2: Variable3: . . . (1,2) (1,5) (4,2) (7,8) (3,88) (6,5) (4,7) (12,4) (4,4) . . . .
2014 Apr 11
6
crear variable en base a nombre de columnas que tienen un 1
Buenos días. Hoy ando un poco (o bastante) espeso y no doy con la tecla de una cosa que seguro que es muy simple.. Pongo un ejemplo. var1 <- c(rep(0,3),rep(1,2)) var2 <- c(rep(1,2),0,0,1) var3 <- c(rep(1,2),rep(0,3)) var4 <- c(rep(1,2),rep(0,3)) datos <- data.frame(fila=1:5,var1, var2, var3, var4) datos datos fila var1 var2 var3 var4 1 1 0 1 1 1 2 2 0
2012 Jan 28
2
Need very fast application of 'diff' - ideas?
Hi everyone, Speed is the key here. I need to find the difference between a vector and its one-period lag (i.e. the difference between each value and the subsequent one in the vector). Let's say the vector contains 10 million random integers between 0 and 1,000. The solution vector will have 9,999,999 values, since their is no lag for the 1st observation. In R we have: #Set up input vector
2010 Jan 12
4
Beginer data.frame
Hello, I use R 2.10, and I am new in R (I used to use SAS and lately Stata), I am using XP. I have a data which has a data.frame format called x.df (read from a csv file). I want to take from this data observations for which the variable "Code" starts with an "R". I took all the Code and put them into a vector vec<-grep("R[A-Z][A-Z]",x.df$Code,value=TRUE) Then I
2014 Apr 11
2
crear variable en base a nombre de columnas que tienen un 1
Carlos, en principio si sería algo así, sólo que en vez de quedarme con todas las columnas var1 a var4 tuviera sólo 3, ya que en mis datos no hay ningún caso que tenga el valor 1 en más de 3 variables.. Había llegado a una solución (mucho menos elegante que usando reshape), que implicaba un for sobre las filas. Jorge, creo que tu solución me vale. Muchas gracias a los dos.. Saludos El
2012 Jan 16
3
Select rows based on multiple comparisons
Dear all, I have a data set in which the same unit appears 2 or 3 or 4 times. I need to aggregate this data to maintain only one unit by row. But I need to do that based on a comparison between the values of such units. I can't find a function to help me on that. I appreciate any help. Below I provide an example of what I want: This is my data: Units Var1 Var2 Var3 1 B 2
2011 Jan 01
3
Plot symbols: How to plot (and save) a graphic symbols originating from a table
Dear all, Please, I have a doubt regarding symbol plotting with data originating from a table. Please, see below: I have a tab delimited file called table1.txt with 4 columns: ypos animal var1 var2 5 cat gina <= lady gina \u2264 lady 7 dog bill >= tony bill \u2265 tony 9 fish dude <= bro dude \u2264 bro #I then load in the data to R: table1<-read.table("table1.txt",
2012 May 31
2
bigglm binomial negative fitted value
Hi, there Since glm cannot handle factors very well. I try to use bigglm like this: logit_model <- bigglm(responser~var1+var2+var3, data, chunksize=1000, family=binomial(), weights=~trial, sandwich=FALSE) fitted <- predict(logit_model, data) only var2 is factor, var1 and var3 are numeric. I expect fitted should be a vector of value falls in (0,1) However, I get something like this:
2009 Sep 21
5
More elegant way of excluding rows with equal values in any 2 columns?
Hello, dear R-ers! I built a data frame "grid" (below) with 4 columns. I want to exclude all rows that have equal values in ANY 2 columns. Here is how I am doing it: index<-expand.grid(1:4,1:4,1:4,1:4) dim(index) # Deleting rows that have identical values in any two columns (1 line of code):
2012 Jan 17
2
Separate ablines in lattice panels
Searched archives and found some old email threads on the topic. But mot exactly what I think I need. Suppose I have a datafile such as tmp. tmp <- data.frame(var1 = c(rnorm(1000), rnorm(1000, 1, 1)), var2 = gl(2, 1000)) I'd like a plot similar to the one below, but with an abline of v=0 in the lower panel and v=1 in the upper panel. Code below creates two lines in each panel, not quite
2011 Apr 14
3
Find number of elements less than some number: Elegant/fast solution needed
Take vector x and a subset y: x=1:10 y=c(4,5,7,9) For each value in 'x', I want to know how many elements in 'y' are less than 'x'. An example would be: sapply(x,FUN=function(i) {length(which(y<i))}) [1] 0 0 0 0 1 2 2 3 3 4 But this solution is far too slow when x and y have lengths in the millions. I'm certain an elegant (and computationally efficient)
2013 Mar 25
2
Plot Matrix with Data
Hi , I would like to use ggplot2 to plot a matrix as an image. You can copy paste the following Data<-matrix(data=rnorm(900,80,20),nrow=30,ncol=30) lengthOut<-5 Lengths<- 15 library(reshape2) library(ggplot2) tdm <- melt(Data) ggplot(tdm, aes(x = Var2, y = Var1, fill = factor(value)),levels=seq(0,1,by=0.1)) +                   labs(x = "MHz", y =
2006 Feb 21
6
How to sum values across multiple variables using a wildcard?
I have a dataframe called "data" with 5 records (in rows) each of which has been scored on each of many variables (in columns). Five of the variables are named var1, var2, var3, var4, var5 using headers. The other variables are named using other conventions. I can create a new variable called var6 with the value 15 for each record with this code: > var6=var1+var2+var3+var4+var5
2009 Feb 07
1
Performing a glm binomial model
Hello R-users, My first consult is that I would like to tackle the relationship between a dependent variable and four environmental factors using a glm binomial model. The problem is that I want to test the interaction between factors too and I would like to learn some way to do it automatically. Now, my syntax is, for instance: E1<-glm(formula = (ENF/TOT)~VAR1+VAR2+VAR3+VAR4, family =
2004 Aug 17
5
Bug in colnames of data.frames?
Hi, I am using R 1.9.1 on on i686 PC with SuSE Linux 9.0. I have a data.frame, e.g.: > myData <- data.frame( var1 = c( 1:4 ), var2 = c (5:8 ) ) If I add a new column by > myData$var3 <- myData[ , "var1" ] + myData[ , "var2" ] everything is fine, but if I omit the commas: > myData$var4 <- myData[ "var1" ] + myData[ "var2" ] the name