similar to: apply with as function ifelse with 2 logical conditions

Displaying 20 results from an estimated 4000 matches similar to: "apply with as function ifelse with 2 logical conditions"

2012 Feb 15
2
function similar to ddply? + calculations based on previous row
Hi all, I was wondering if there is a function kind of similar that splits a dataframe, applies a function to each row and returns in a data frame. I know ddply but this one isn?t useful in this situation. I have a dataframe with values for each day (rows) for different objects (columns). I have values for several years. Now, I want to do calculations on only the data of that year. With the
2012 Feb 13
2
different way for a for loop for several columns?
Hi, I have a question about repeating something for several columns. I calculated a lot of values for different objects. The values are normally calculated step-wise for every day for each object. With this obtained data frame, I make further calculations. Here I have to calculate some things and I have to take into account the years because I want a number for each year. I do these first for one
2012 Jun 05
1
nls: how do you know if the model is significant?
Hi all, I'm struggling with nls. How do you know if your model is significant? For a lm, you get a p-value, but you don't get it for a nls. Is there a way to calculate it? For a lm I use this: a<-summary(lm(model ~obs)) f.stat<-a$fstatistic p.value<-1-pf(f.stat["value"],f.stat["numdf"],f.stat["dendf"]) Is there something similar for a nls?
2012 Jan 17
2
result numeric(0) when using variable1[which(variable2="max(variable2)"]
Dear all, I have a question about the knowing for which row I have the max value of one of my variables. I calculated the Rsquared for different columns and made a list to gather them. I unlisted this list to create a vector with this values. I want to know for which column I have the max value of Rsquared. The columns were always named in the same way. They always start with results4$depth_
2012 Jun 04
2
Non-linear curve fitting (nls): starting point and quality of fit
Hi all, Like a lot of people I noticed that I get different results when I use nls in R compared to the exponential fit in excel. A bit annoying because often the R^2 is higher in excel but when I'm reading the different topics on this forum I kind of understand that using R is better than excel? (I don't really understand how the difference occurs, but I understand that there is a
2012 Mar 13
1
size of graphs when using multiple figures by row
Hi all, I have a basic question concerning graphs in R. I?m using the par() function and I?m working with multiple figures by row (mfrow) but my the hight of my figures become compressed. I have 4 rows and 2 columns (because I want to plot 8 histograms (freq = FALSE ) on it. I know I can adapt my margins with for example ?oma? and ?mai? but I don?t know how to choose the size of the figure? I
2012 Jan 18
3
manipulating data of several columns simultaneously
Dear all, I have a question concerning manipulating data of several columns of a dataframe at the same time. I manage to do it for one column (with the use of the specific name for this column). In each columns, I have 60 values. But I should reorganize the values (because I created this as an output before and I want to compare it with an other dataset). I want that the value on row 2 becomes
2010 Aug 02
3
Using apply for logical conditions
Hi, I've got some boolean data in a data.frame in the form: X Y Z A B C [1] T T F T F F [2] F T T F F F . . . What I want to do is create a new column which is the logical disjunction of several of the columns. Just like: new.column <- data$X | data$Y | data$Z However I don't want to hard code the particular columns into the
2006 Oct 09
0
dispatch on functions (was: Re: ifelse(logical, function1, function2) does not work)
On 10/7/06, Gabor Grothendieck <ggrothendieck at gmail.com> wrote: > I have noticed that dispatch on functions seems not to work > in another case too. We define + on functions (I have ignored > the niceties of sorting out the environments as we don't really > need it for this example) but when we try to use it, it fails even > though in the second example if we run it
2012 Jan 26
1
Error in ifelse(append, "a", "w") : , (list) object cannot be coerced to type 'logical'
Hello I will appreciate your help with the following. Running a script in R 2.14.1 under windows vista I get the following error message: Error in ifelse(append, "a", "w") : (list) object cannot be coerced to type 'logical' However, the very same script runs perfectly well under Ubuntu. My understanding is that this type of error is associated to
2006 Oct 07
3
ifelse(logical, function1, function2) does not work
Why this kind of assignment does not work? n <- 1 f <- ifelse(n == 1, sin, cos) f(pi) this must be rewritten as: n <- 1 f <- cos if (n == 1) f <- sin f(pi) [oops. 1.224606e-16 instead of zero. Damn floating point errors :-/] Alberto Monteiro
2004 Feb 09
0
apply on logical data frame together with all (PR#6560 )
Wrap your data frame in data.matrix() and you should be fine; e.g., apply(data.matrix(df), 1, all) Don't think this qualifies as bug... Andy > From: roland.puntaier@chello.at > > Full_Name: Roland Puntaier > Version: 1.8.1 > OS: Windows XP > Submission from: (NULL) (62.99.238.78) > > > I have a data frame with some columns being logical. > I wanted to
2004 Feb 09
0
apply on logical data frame together with all (PR#6560
Wrap your data frame in data.matrix() and you should be fine; e.g., apply(data.matrix(df), 1, all) Don't think this qualifies as bug... Andy > From: roland.puntaier@chello.at > > Full_Name: Roland Puntaier > Version: 1.8.1 > OS: Windows XP > Submission from: (NULL) (62.99.238.78) > > > I have a data frame with some columns being logical. > I wanted to
2004 Feb 09
2
apply on logical data frame together with all (PR#6560)
Full_Name: Roland Puntaier Version: 1.8.1 OS: Windows XP Submission from: (NULL) (62.99.238.78) I have a data frame with some columns being logical. I wanted to calculate a column that is an AND combination of the other logical columns. I tried to use apply(df,1,all) It did not work because of the implicit string conversion. So I made the functions All<-function(...)
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)))
2009 Nov 04
3
inconsistent behavior for logical vectors when using apply (" TRUE")
Hello, > X <- data.frame(letters=letters[1:3], flag=c(TRUE, FALSE, TRUE)) > X letters flag 1 a TRUE 2 b FALSE 3 c TRUE > apply(X, 1, as.list) [[1]] [[1]]$letters [1] "a" [[1]]$flag [1] " TRUE" [[2]] [[2]]$letters [1] "b" [[2]]$flag [1] "FALSE" [[3]] [[3]]$letters [1] "c" [[3]]$flag [1] " TRUE"
2012 Jan 11
3
Accomplishing a loop on multiple columns
Hello, I have a question concerning ?for loops? on multiple columns. I made 91 columns with results (all made together with a for loop) and I want to us lm to fit the model. I want to compare the results of all these calculated columns (91) with one column with observed values. I use the function lm to fit the model and calculate r.squared. I manage to do this for each column separately: For
2010 Jul 20
1
ifelse() and missing values in test conditions
R experts, I have been unable to get the following ifelse statement to work as desired when applied to my data frame. Example: DF$ANYEF <- with(DF,ifelse(PSOUGHT1=='ANY'|PSOUGHT2=='ANY'|PSOUGHT3=='ANY',PEFF,0)) ##### this statement will be replicated 16 times for 16 unique _EF variables ### Basically, I want each ANYEF for each row to equal the corresponding row
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 Mar 10
1
ifelse logic and multiple assignments
I'm a fairly new R user and while I have a solution to my problem I'm wondering if there is a better one. In SAS it's common to use if/then logic along with a "do" statement to make several things happen. While I could do the same thing in R using a "for" loop, and "if" and {}, I've read that loops are less common in R and I wonder if I'm doing