similar to: [Q] Setting elements of a vector

Displaying 20 results from an estimated 4000 matches similar to: "[Q] Setting elements of a vector"

2006 Apr 15
1
Removing Rows/Records from a Table
I would like to selectively remove rows from a table. I had hoped that I could create a table and selectively add rows with something like > NewTable<-table(nrow=100, ncol=4) > NewTable[1,]<-OldTable[10,] but that doesn't work. The former call gives > NewTable ncol nrow 4 100 1 while the latter call gives a table the length of OldTable. Making a matrix, m, with the
2010 Jul 12
2
findInterval and data resolution
Hello Wise Ones... I need a clever way around a problem with findInterval. Consider: vec1 <- 1:10 vec2 <- seq(1, 10, by = 0.1) x1 <- c(2:3) a1 <- findInterval(x1, vec1); a1 # example 1 a2 <- findInterval(x1, vec2); a2 # example 2 In the problem I'm working on, vec* may be either integer or numeric, like vec1 and vec2. I need to remove one or more sections of this vector;
2011 Jun 03
2
Arules: R Crashes when running eclat with tidLists=TRUE
Hello, I'm using the eclat function of the arules package (1.0-6) for the identification of frequent itemsets. I need the tidLists, but if I set in the function tidLists=TRUE R crashes (Windows XP Professional SP3, 32 bit, R version 2.12.1 (2010-12-16), reproducible on two different computers) with two different error messages or non at all. Minimum examples are: library(arules)
2013 Apr 25
2
Selecting and then joining data blocks
Hi all, I have 4 matrices, each having 5 columns and 4 rows .....denoted by B1,B2,B3,B4. I have generated a vector of 7 indices, say (1,2,4,3,2,3,1} which refers to the index of the matrices to be chosen and then appended one on the top of the next: like, in this case, I wish to have the following mega matrix: B1over B2 over B4 over B3 over B2 over B3 over B1. 1> How can I achieve this?
2009 Feb 19
1
code patterns in vector
Dear List, I have this column/vector: vec <- c("function", "missing", "string") and want to compute a second column/vector: - value if the pattern "unc" is found: 1 - value if the pattern "iss" is found: 2 - value if none of the patterns is found: 0 This should be the result: > vec2 [1] 1 2 0 Any help? Tried it with grep, but the output
2010 Aug 24
3
multiple assignments ?
Simple one, have read and googled, still no luck! I want to create several empty vectors all of the same length. I would like multiple empty vectors (vec1, vec2, vec3) and want to create them all in one line. I've tried vec1,vec2,vec3 <- vector(length=5) and c(vec1,vec2,vec3) <- vector(length=5) and several other attempts but nothing seems to work ... suggestions? Thanks Jim
2012 Oct 08
1
Any better way of optimizing time for calculating distances in the mentioned scenario??
Dear All, I'm dealing with a case, where 'manhattan' distance of each of 100 vectors is calculated from 10000 other vectors. For achieving this, following 4 scenarios are tested: 1) scenario 1: > x<-read.table("query.vec") > v<-read.table("query.vec2") > d<-matrix(nrow=nrow(v),ncol=nrow(x)) > for (i in 1:nrow(v)){ + d[i,]<-
2013 Jun 18
1
transform 3 numeric vectors empty of 0/1
Dear all, Without a loop, I would like transform 3 numeric vectors empty of 0/1 of same length Vec1 : transform 1 to A and 0 to "" Vec2 : transform 1 to B and 0 to "" Vec3 : transform 1 to C and 0 to "" to obtain only 1 vector Vec who is the paste of the 3 vectors (Ex : ABC, BC, AC, AB,...) Any idea ? Thank you for your help -- Michel ARNAUD
2009 Jun 22
2
Help on creating a sequence of vectors
I want to create a number of vectors like : vec1 <- rnorm(1) vec2 <- rnorm(2) vec3 <- rnorm(3) and so on........... Here I tried following : for (i in 1:10) paste("vec", i, sep="") <- rnorm(i) However obviously that is not working. Here vectors I need to be seperated i.e I do not want to create a "list". How to modify above code? -- View this
2002 Jun 18
5
insert number in vector
Hello R-users, I need to create a vector inserting an 1 after each value of another vector. For example: vec1<-c(2,3,4) I need to create a vector with the values 2,1,3,1,4 Does anyone know how create this vector without loops (vec1 could have 1000 elements) Thank you, Juan -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read
2008 Oct 20
2
R Newbie Question
Hello list, I just started R today and tried something quite simple. I wanted to create a colored plot and eventually after hours of fiddling around got it working. However, my solution seems very suboptimal and I'd really appreciate your hints on how to improve. I believe that R already offers many functions I coded (e.g. distance between two vectors, vector length, vector normalization and
2008 Mar 05
3
regex sulotion for seperating number and string
I have strings contain postcode and letters, some seperated with blank, some with comma, and some hasn't seperated. eg, "2324gz" "2567 HK" "3741,BF" I want to seperate the number and letters into two new variables. I know this should be quite basic question, but searched on regex syntax and that seems a bit scarey to me, any one can shot me a quick solution
2007 Feb 01
2
Losing factor levels when moving variables from one context to another
Hi, there I'm currently trying to figure out how to keep my "factor" levels for a variable when moving it from one data frame or matrix to another. Example below: vec1<-(rep("10",5)) vec2<-(rep("30",5)) vec3<-(rep("80",5)) vecs<-c(vec1, vec2, vec3) resp<-rnorm(2,15) dat<-as.data.frame(cbind(resp, vecs))
1999 Dec 16
2
R question
I have the following question, which is elementary but I am unable to answer. In a for(i=10) loop, I am trying to represent the 10 1-dimensional vectors l1, l2,... l10 by some expression that will run through these values. ie. soppose I want to add l1 + ... + l10 I could go x <- 0 for(i in 1:10){ x <- x+ l(i)} This should return x to be the sum of the 10 li's for i from 1 to 10
2005 Jan 07
3
lognorm
Hi! I 've a problem to have a lognorm distribution with mean=1 and var (or sigma)=1. rlnorm(1000,0,0) rlnorm(1000,1,1) rlnorm(1000,0,1) .... ? Can you help me?
2008 Nov 18
2
random value changes in a vector
To clear up a question regarding my earlier posting regarding random changes in a vector: Say you have a vector (1, -1, -1, 1, 1, -1). I want each value in the vector to have a probability that it will change signs when this vector is regenerated. For example, probability = 50%. When the vector is regenerated, the first value in the vector (1) has a 50% chance of switching to -1. If I
2012 Aug 24
6
updating elements of a vector sequentially - is there a faster way?
I would like to know whether there is a faster way to do the below operation (updating vec1). My objective is to update the elements of a vector (vec1), where a particular element i is dependent on the previous one. I need to do this on vectors that are 1 million or longer and need to repeat that process several hundred times. The for loop works but is slow. If there is a faster way, please let
2013 Apr 22
1
Print occurrence / positions of words
Hi, May be this helps: vec<- "this is a nice text with nice characters" library(stringr) ?vec2<-unlist(str_match_all(vec,"\\w+")) #or # vec2<-str_split(vec," ")[[1]] res<-unique(lapply(vec2,function(x) which(!is.na(match(vec2,x))))) ?names(res)<- unique(vec2) res #$this #[1] 1 # #$is #[1] 2 # #$a #[1] 3 # #$nice #[1] 4 7 # #$text #[1] 5 # #$with #[1]
2012 Oct 11
3
Sorting a data frame by specifying a vector
Hello all, I cannot seem to figure out this seemingly simple procedure. I want to sort a data frame by a specified character vector. So for : df.. <- data.frame(Season=rep(c("Summer","Fall","Winter","Spring"),4),Obs= runif(length(rep(c("Summer","Fall","Winter","Spring"),4)))) I want to sort the data frame
2012 Oct 12
1
Problem with which function
Hej, i need the which() funktion to find the positions of an entry in a matrix. the entries i'm looking for are : seq(begin,end,0.01) and there are no empty spaces i'm searching in the right range. so i was looking for the results R can find and i recieved this answer. for (l in