similar to: test if vector contains elements of another vector (disregarding the position)

Displaying 20 results from an estimated 60000 matches similar to: "test if vector contains elements of another vector (disregarding the position)"

2012 Jan 21
2
sequentially summing up a elements of a vector
Hi, I have a somewhat abstract and tricky problem (at least for me). Perhaps someone here can help me: I would like to convert: x <- c(0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0) into x <- c(0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4) every 1 in x marks kind of a 'border' which is separated in different 'regions' in the
2012 Feb 02
1
get mean of same elements in a data.frame
Hi, I have the following data.frame: data.frame(x = c(1:10), y = rnorm(10,2,1), label = rep(c('a', 'b', 'c', 'd', 'e'),2)) in this data.frame there is a label-variable containing strings. Each string is represented two times. Now I would like to have the mean of the corresponding x (and y-values) for every unique label-element. For the label
2013 Feb 26
4
cut a vector in equal parts
Hi, I would like to cut a vector of values in parts. Each part should have an equal number of elements. for example: x <- (rnorm(500)^2) now I want 5 vectors each with 100 elements. The first vector should include the 100 lowest values of x and so on (so that the fifth vector contains the 100 highest values of x). thanks for any help!
2009 Sep 23
2
Function to check if a vector contains a given value?
Dear R'rs, is there a function that checks if a given vector contains a certain value. E.g., x<-c(1,2,3,4). How can I get a TRUE or FALSE for whether x contains a 2? -- Dimitri Liakhovitski Ninah.com Dimitri.Liakhovitski at ninah.com
2011 Oct 10
1
calculate multiple means of one vector
Dear R-Users, I have the following two vectors: data <- rnorm(40, 0, 2) positions <- c(3, 4, 5, 8, 9, 10, 20, 21, 22, 30, 31, 32) now I would like to calculate the mean of every chunk of data-points (of the data-vector) as defined by the positions-vector. So I would like to get a vector with the mean of element 3 to 5 of the data-vector, 8 to 10, 20 to 22 and so
2010 Feb 09
3
split strings in a vector and convert it to a data.frame
hi, I have a vector full of strings like; xy_100_ab xy_101_ab xy_102_ab xy_103_ab I want to seperate each string in three pieces and the separator should be the "_" at the end I want a data.frame like: column1 column2 column3 xy 100 ab xy 101 ab xy 102 ab xy 103 ab I tried strsplit but I couldn't figure out how to convert the list I get into a data.frame. I just
2011 Sep 09
3
split variable / create categories
Hi, is there a function or an easy way to convert a variable with continuous values into a categorial variable (with x levels)? here is what I mean: I want to transform x: x <- c(3.2, 1.5, 6.8, 6.9, 8.5, 9.6, 1.1, 0.6) into a 'categorial'-variable with four levels so that I get: [1] 2 2 3 3 4 4 1 1 so each element is converted into its rank- value / categorial-value (in
2011 Oct 05
2
mean of 3D arrays
Hi, I have multiple three dimensional arrays. Like this: x1 <- array(rnorm(1000, 1, 2), dim=c(10, 10, 10)) x2 <- array(rnorm(1000, 1, 2), dim=c(10, 10, 10)) x3 <- array(rnorm(1000, 1, 2), dim=c(10, 10, 10)) Now I would like to compute the mean for each corresponding cell. As a result I want to get one 3D array (10 x 10 x 10) in which at position x, y, z is the mean of the
2012 Dec 25
5
aggregate / collapse big data frame efficiently
Hi, I need to aggregate rows of a data.frame by computing the mean for rows with the same factor-level on one factor-variable; here is the sample code: x <- data.frame(rep(letters,2), rnorm(52), rnorm(52), rnorm(52)) aggregate(x, list(x[,1]), mean) Now my problem is, that the actual data-set is much bigger (120 rows and approximately 100.000 columns) ? and it takes very very long
2008 Jul 10
2
Position in a vector of the last value > n
This shouldn't be hard, but it's just not coming to me: Given a vector, e.g., v <- c(20, 134, 45, 20, 24, 500, 20, 20, 20) how can I get the index of the last value in the vector having a value greater than n, in this case, greater than 20? I'm looking for an efficient function I can use on very large matrices, as the FUN argument in the apply() command. Confidentiality
2013 Jan 11
3
aggregate data.frame based on column class
Hi, When using the aggregate function to aggregate a data.frame by one or more grouping variables I often have the problem, that I want the mean for some numeric variables but the unique value for factor variables. So for example in this data-frame: data <- data.frame(x = rnorm(10,1,2), group = c(rep(1,5), rep(2,5)), gender =c(rep('m',5), rep('f',5))) aggregate(data,
2010 Feb 25
1
Accessing named elements of a vector
Dear R developers, A great R feature is that elements of vectors, lists and dataframes can have names: vx = c(a=1, b=2) lx = list(a=1, b=2) Accessing element "a" of vx: vx['a'] Accessing element "a" of lx: lx[['a']] or lx$a Might be a matter of taste, but I like the $ very much. Unfortunately, vx$a is not functional. Would it break existing compatibility
2011 Oct 05
3
do calculations as defined by a string / expand mathematical statements in R
Dear R-group, is there a way to perform calculations that are defined in a string format? for example I have different variables: x1 <- 3 x2 <- 1 x4 <- 1 and a string-variable: do <- 'x1 + x2 + x3' Is there any way to perform what the variable 'do'-describes (just like the formula-element but more elemental)? Perhaps my idea to solve my problem is a little
2012 Jan 29
2
apply lm() to each row of a matrix
Hi, I would like to fit lm-models to a matrix with 'samples' of a dependent variable (each row represents one sample of the dependent variable). The independent variable is a vector that stays the same: y <- c(1:10) x <- matrix(rnorm(5*10,0,1), 5, 10) now I would like to avoid looping over the rows, since my original matrix is much larger; for(t in 1:dim(x)[1]) {
2009 Jul 11
2
mann-whitney U-test - U-value
Hi, I know that I can perform a Mann-Whitney U test with wilcox.test(x,y) But instead of an U-value I get a W-Value. Is it possible to change this?
2009 Nov 18
2
error message; ylim + log="y"
Hi, I get a lot of error messages with this command, but I don't understand why; plot(c(),c(), xlim=c(1,10), ylim=c(0,10000), log="y") thanks for any help! [[alternative HTML version deleted]]
2009 Mar 05
3
text at the upper left corner outside of the plot region
Hi, is there a way to place text at the upper left corner (or another corner) of the plot? I want to place it really at the upper left corner of the whole plot (the file I get), not at the upper left corner of the plot-region. I tried text() and mtext(), and corner.label() of the plotrix package but it didn't work out. thanks!
2011 Oct 11
2
replicate data.frame n times
Hi, is there a way to replicate a data.frame like you can replicate the entries of a vector (with the repeat-function)? I want to do this: x <- data.frame(x, x) (where x is a data.frame). but n times. And it should be as cpu / memory efficient as possible, since n is pretty big in my case. thanks for any suggestions!
2008 Mar 14
2
Selecting elements in vector
Hi Consider the following code > x <- rep(1:13, 13) > y <- 1:3 I want to select all elements in x which are equal to 1, 2 or 3. I know that I could use > sel <- x==y[1] | x==y[2] | x==y[3] > x[sel] to obtain the values, but in my analysis, the y-vector is thousands of elements long. Is there any way, that I can do that easily? Thanks Rainer -- Rainer M. Krug, Dipl.
2008 Feb 12
3
reverse vector elements
Dear lists, I want to write a function of a vector and reverse the order of its elements. Here is my code: revector<-function(n){ y=vector(length=n) for(i in n:1){ y[i]=i } return(y) } i want my output to be like this: y [1] 10 9 8 7 6 5 4 3 2 1 Any suggestion?? Thanks!! Cheers, Anisah ---------------------------------