similar to: Why doesn't this work ?

Displaying 20 results from an estimated 30000 matches similar to: "Why doesn't this work ?"

2009 Mar 23
3
Replacing a few variable values within a DataFrame...
I would like to replace a few varaibles within a data frame. For example, in the dataframe below (contrived) I would like to replace the current housesize value only if the Location is HSV. However, I would like to leave the other values intact. I tried "ifelse", but I don't really need the else condition. test_data2_df<-data.frame(Variables=c("SQR
2008 Jun 27
4
Recoding
Hi! Given a vector (or a factor within a df),i.e. v1 <- c(1,1,1,2,3,4,1,10,3) and a dictionary cbind(c(1,2,3),c(1001,1002,1003)) is there a function (on the same line than recode() in car) to get v2 as c(1001,1001,1001,1002,1003,4,1001,10,1003) ? I'm using myself a function based on match() since long ago (I think that thanks to advice by Prof. B. Ripley), but would like to know if there
2010 Feb 28
1
Combining 2 columns into 1 column many times in a very large dataset
*Combining 2 columns into 1 column many times in a very large dataset* The clumsy solutions I am working on are not going to be very fast if I can get them to work and the true dataset is ~1500 X 45000 so they need to be efficient. I've searched the R help files and the archives for this list and have some possible workable solutions for 2) and 3) but not my question 1). However, I include
2007 Nov 12
4
a repetition of simulation
Hello, I have a simple (?) simulation problem. I'm doing a simulation with logistic model and I want to reapet it 600 times. The simulation looks like this: z <- 0 x <- 0 y <- 0 aps <- 0 tiss <- 0 for (i in 1:500){ z[i] <- rbinom(1, 1, .6) x[i] <- rbinom(1, 1, .95) y[i] <- z[i]*x[i] if (y[i]==1) aps[i] <- rnorm(1,mean=13.4, sd=7.09) else aps[i] <-
2009 Sep 08
3
Mapping factors to a new set of factors
Hello, I am trying to map a factor variable within a data frame to a new variable whose entries are derived from the content of the original variable and there are fewer factors in the new variable. That is, I'm trying to set up a surjection. After first thinking that this would be a common operation and would have a quite simple interface, I can not seem to find one, nor any similar posts
2011 Feb 26
2
how to remove rows in which 2 or more observations are smaller than a given threshold?
Hello The data set I am examining has 7425 observations (rows with unique identifiers) and 46 samples(columns). I have been trying to generate a dataset that filters out observations that are "negligible" The definition of "negligible" is absolute value less or equal to 1.58. The rule that I would like to adopt to create a new data is: drop rows in which 2 or more
2011 Apr 29
3
why doesn't ifelse work ?
I have the following lines of code: ind <- rollapply(GSPC, 200, mean) signal <- ifelse(diff(ind, 5) > 0 , 1 , -1) signal[is.na(signal)] <- 0 I never get a value of -1 for signal even though I know diff(ind , 5) is less than zero frequently. It looks like when diff(ind , 5) is less than zero, signal gets set to 0 instead of - 1. Any ideas why ? Here's some information on ind and
2010 Nov 04
4
how to work with long vectors
HI, Dear R community, I have one data set like this, What I want to do is to calculate the cumulative coverage. The following codes works for small data set (#rows = 100), but when feed the whole data set, it still running after 24 hours. Can someone give some suggestions for long vector? id reads Contig79:1 4 Contig79:2 8 Contig79:3 13 Contig79:4 14 Contig79:5 17
2011 Jan 30
1
Extract subsets of different and unknown lengths from huge dataset
Dear prospective reader, I apologize for posting my problem but I've just no idea how to go on by processing this huge (over 70 MB) dataset. Thank you in advance for any help or comment! I do appreciate it! My textfile contains 1 column of interest (numbers/values only). The overall issue is to extract 'events', starting points of which are defined by at least 24 preceding values
2009 Mar 11
4
R-help: grep in for loop using index - doesn't work
Hi everyone I am trying to use grep in a for loop to compare a string value. It works if I use the actual index value but when I use the for loop index, it doesn't work. Any suggestions plz. Here is the code: data <- read.table(file="Sigmoid.csv", head=FALSE, sep=","); c1 <- data$V1 c2 <- data$V2 c3 <- data$V3 c1data <- data.frame(c1); c2data <-
2011 Feb 02
4
Testing whether a number belong to a set
Hello everyone, I am stuck with an apparently simple issue : i) I have two sets S1 and S2, each containing a large number of integers, say zip codes. ii) Now, I just want to test whether a particular zip code belong to S1 or S2 or neither of them. iii) If it belongs to S1, the area/region gets a particular label, say 1; if it belongs to S2, it gets a label 2 and if it doesnot belong to either S1
2010 Oct 01
2
element wise conditional assignment in r
Hi, I am looking for a one-liner code for the following situation say I have a vector r of 0 and 1's, and another vector v of equal length. I want to assign v[i]-1 to v[i] if r[i]=1, for all i. How would I do that using mapply or any other batch processing keywords? thanks. John -- View this message in context:
2009 Nov 30
3
Assign palette (e.g. rainbow) to a series of points on 1 plot
I have 11 vectors representing insect survival probabilities in response to different levels of toxins at 10 concentrations lx100=c(1,1,1,.8,.5,.4,.2,0) day100=c(0,1,2,3,4,5,6,7,8) lx90=c(1,1,1,1,.9,.8,.6,.4,.2,.1,0) day90=c(0,1,2,3,4,5,6,7,8,9,10) #...and so on10% and a zero (control) series lx0=c(1,1,1,1,1,1,.9,.9,.8,.8,.6,.5,.4,.3,.2,.1,.1,0)
2011 Mar 29
1
new syntax: bash-like pipe operator
Dear R Community, One thing that always bugged me about R is the abundance of multi-level nested statements, like: cumsum(ifelse(c(1,diff(v)),1,0)) because: a) you have to read them inside out as opposed to left-to-right b) in the console you always have to go back and type the parenthesis if you want to nest your statement I kind of like the UNIX pipe operator as a very good abstraction of a
2009 Feb 13
2
extracting parts of words or extraxting letter to use in ifelse-func.
Hello I want to make some variables with the ifelse-function, but i don't know how to do it. I want to make these five variables; b2$PRRSvac <- ifelse(b2$status=='A' | b2$status=='Aa',1,0) b2$PRRSdk <- ifelse(b2$status=='B' | b2$status=='Bb',1,0) b2$sanVac <- ifelse(b2$status=='C' | b2$status=='sanAa',1,0) b2$sanDk <-
2010 Sep 16
3
If statements for multiple arrays
Hello, I wrote this code which works fine on a single observation: x<-100 y<-200 z<-125 aa<-150 if(x<z && y>z) {aa-z} result: 25 I am trying to apply this logic where x,y,z,and aa are arrays but with very little success. I have tried using loops and whiles but I always get errors of various types. I have consulted a few manuals but with limited success. My hopeful
2009 Aug 26
1
Batch replacement, by factor, of values in a data frame
Dear List, I'm wondering if there is a better/cleaner/more efficient way of replacing 0 values in a variable with the minimum of the non-missing and non-zero values of that same variable, but doing it within the levels of a factor? Consider the dummy example data presented at the end of my message. Within each 'Site' there are some 0 values and possibly some NA's. I can compute
2008 Dec 30
3
Componentwise means of a list of matrices?
Dear useRs, I have a list, each entry of which is a matrix of constant dimensions. Is there a good way (i.e., not using a for loop) to apply a mean to each matrix entry *across list entries*? Example: foo <- list(rbind(c(1,2,3),c(4,5,6)),rbind(c(7,8,9),c(10,11,12))) some.sort.of.apply(foo,FUN=mean) I'm looking for a componentwise mean across the two entries of foo, i.e., the
2012 Aug 02
2
metafor- interpretation of moderators test for raw proportions
Hello metafor users, I'm using metafor to perform a single-effect summary estimate of the raw proportion of patients experiencing a post-operative complication, and I'm interested in seeing if this proportion differs between the three most commonly used surgical techniques. The software is working as expected, but I would like to double check on the interpretation of my mixed-effect model
2010 Aug 13
6
Equality of Vectors
Hello, Is there a way to get a single TRUE or FALSE statement from comparing two vectors? For example, c(1,2,3) == c(1,2,3) produces TRUE TRUE TRUE where I would like it to produce only TRUE for use in an if statement. Likewise, when two vectors are not exactly identical (in all elements) I would like a single FALSE result, as opposed to c(1,2,3) == c(1,2,5) TRUE TRUE FALSE Any ideas?