Displaying 20 results from an estimated 20000 matches similar to: "And Statement for two if functions"
2013 Mar 11
3
New Stack
Hi Experts, I am newbie in R. Could you please share your idea to create a stack with no value or zero value? Nrow=1,Ncol=1, Ncell=1, I aim to work with looping, I want to make a first layer with zero values to add other layers further. Thanks.
Best Regards,
..................Anup KhanalNorwegian Institute of science and Technology (NTNU)Trondheim, NorwayMob:(+47) 45174313
2010 Feb 23
3
how to rearrange a dataframe
Hi all,
I'd appreciate if anyone can help me with this...
I have a data frame that looks like this:
1 + name1 1 2 3
2 + name2 5 9 10
2 - name3 56 74 93
1 - name4 65 75 98
I need to rearrange this in a way so that the rows with "1" in the
first column, and "-" in the second column; then columns 4 and 6
should switch places. That is, column 6 would be now column 4 and
2016 Apr 26
3
Missing Values in Logical Expressions
Hi All,
I need to evaluate missing values in my data. I am able to filter these
values and do simple statistics on it. But I do need new variables based
on variables with missing values in my dataset:
Check_Kunde_2011 <- ifelse(is.na(Umsatz_2011) == TRUE & Kunde_2011 == 1,
1, 0)
Check_Kunde_2011 <- factor(Check_Kunde_2011, levels = c(1,0), labels =
c("Check",
2012 Jan 17
2
Prediciting sports team scores
I am working on predicitng the scores for a days worth of matches of team
sports. I have already collected data for the teams for the season we are
concentrating on.
I have been fitting poisson models for football games and have worked out
what model is best and which predictor variables are most important.
We would now like to predict the probability distribution for the scores for
each team.
2010 Dec 09
1
set dataframe field value from lookup table
Hi
This is (hopefully) a bit more cogent phrasing of a previous post. I'm
trying to compute a z-score to rows in a large dataframe based on values in
another dataframe. Here's the script (that does not work). 2 questons,
1) Anyone know of a more elegant way to calculate the "rounded" age value
than the nested ifelse's I've used?
2) how to reference the lookup table
2012 Mar 05
1
Trouble with a loop
I am trying to run this loop but it keeps coming up with the following error:
'Error: no function to return from, jumping to top level'
n.simul <- 1000
A <- {for(i in 1:12){{
nT <- rpois(n.simul, T[i])
nP <- rpois(n.simul, P[i])
nD <- rpois(n.simul, D[i])
nC <- rbinom(n.simul, nT, C[i])
Score <- (5*nT + 2*nC + 3*nP + 3*nD)
}
return(Score)}}
My aim is to calculate
2016 Apr 26
0
Missing Values in Logical Expressions
Hm
Based on Jim's data your construction gives me correct result.
> Umsatz_2011<-c(1,2,3,4,5,NA,7,8,NA,10)
> Kunde_2011<-rep(0:1,5)
> Check_Kunde_2011 <- ifelse(is.na(Umsatz_2011) == TRUE & Kunde_2011 == 1, 1, 0)
> Check_Kunde_2011 <- factor(Check_Kunde_2011, levels = c(1,0), labels = c("Check", "OK"))
> table(Check_Kunde_2011)
2005 Jun 22
2
Trouble with ifelse and if statement (PR#7962)
Full_Name: Woolton Lee
Version: 2.1
OS: windows
Submission from: (NULL) (128.118.224.46)
I did the following ('g' and 'h' are both numeric vectors)
> i <- abs(g-h)
creating a vector 'i' with values,
> i
[1] 0.08 0.00 0.33 0.00 0.00 0.00 0.00 0.33 0.00 0.00 0.08 0.08 0.20 0.00 0.13
Now, I want to create a new vector =1 whenever 'i' = 0.33 and =0
2012 Aug 04
3
Questionnaire Analysis virtually without continuous Variables
Hello!
I am doing an analysis on a questionnaire of hunters taken in 4
different districts of some mysterious foreign country. The aim of the
study was to gather info on the factors that determine the hunting
success of a peculiarly beautiful bird in that area. All variables are
factors, i.e. they are variables such as "Use of Guns - yes / no", "Use
of Dogs - yes / no" and
2007 Jan 19
3
if else statement
Hello,
I'm doing some scripting and I've noticed that R doesn't seem to
have an
if (cond){
do
}ifelse (cond) {
do
} else {
do
}
type block.
Is this correct or am I missing something.
THX
Paul
--
Research Technician
Mass Spectrometry
o The
/
o Scripps
\
o Research
/
o Institute
2012 Nov 21
4
help with if statement
Hi all,
I had a dataset A like:
TIME DV
0 0
1 10
5 20
24 30
36 80
48 60
72 15
I would like to add 24 to those values higher than 24 in the TIME column.
I did the following:
If (A$TIME>=24) {
A$TIME <- A$TIME+24}
It did not work. How should I do it?
Thanks,
--
View this message in context: http://r.789695.n4.nabble.com/help-with-if-statement-tp4650315.html
Sent from the
2011 Sep 16
3
Problematic If-Else statement
Hi guys,
My code (next 2 lines below) isn't doing what I'm expecting it to:
tmp <-
ifelse(uncurated$days_to_tumor_recurrence=="null","norecurrence","recurrence")
curated$recurrence_status <- tmp
I want the column "recurrence_status" in my output file to have values
"recurrence" (if the input value had a number in the
2013 Jan 01
1
Order variables automatically
Hi,
I have a dataset with 6 categorical variables. I have used this following code to make the variables u1-u6 ordered factors and this works well.
cat1cat2 cat3 cat4 cat5 cat6
? 0 ? ?? 1 ? ? 1????? 0 ??? 0? ?? 1
? 1 ? ?? 1 ? ? 0 ? ?? 0 ? ? 0 ? ? 0
.......
....
############
data<-read,table("example.txt")
data <- as.data.frame(lapply(data, ordered))
############
Now,
2009 Oct 27
1
New vector based on if/else statement within for loop?
Hello,
I am trying to create a new vector (w) that is based on comparing two
vectors (P and Z). The compaison is simple (I created a for loop that
reassigns w based on if statement), all Z values >= 24 and P values <=1,
w=88 else w=77. I am not getting the correct results for w, see
example code below. Any thoughts or suggestions on the correct method.
Thank you,
Doug
P <-
2012 Mar 07
3
if statement
Hi All,
I have one difficulty in using the conditional if statement
Assume ,
x <- -1:4
x
[1] -1 0 1 2 3 4
if x is lees than want I want to add 1 and I used the following command
if(x<0) {x=x+1}
Warning message:
In if (x < 0) { :
the condition has length > 1 and only the first element will be used
> x
[1] 0 1 2 3 4 5
That command added 1 to each element.
But I want
2009 Oct 03
3
else if statement error
Hello,
I am doing a simple if else statement in R. But it always comes out error
such as 'unexpected error'
There are two variables. ini and b. when ini=1, a=3; when ini>1 and b>2,
a=5; all other situations, a=6. I don't know where it is wrong.
Here is my code
ini=3
b=4
if (ini==1) {
a=3
}
else if (ini>1 and b>2 ) {
a=5
}
else {a=6}
Thanks a
2002 Sep 19
5
how to use if statement in function correctly
Dear all
I try to persuade if statement in my function to work as I want (but I am not very
successful:(
My question is why my function with if statement is evaluated correctly in case of
atomic variables and incorrectly in case of vector variables.
Here is an example:
#function with if statement
fff <- function(otac,sklon)
{
test <- (otac *
2007 Jan 21
1
identify selected substances across individuals
An embedded and charset-unspecified text was scrubbed...
Name: inte tillg?nglig
Url: https://stat.ethz.ch/pipermail/r-help/attachments/20070121/436ed377/attachment.pl
2011 Mar 21
3
Computing row differences in new columns
Hi
I have the following columns with dates and results, sorted by subject and date. I'd like to compute the differences in dates and results for each patient, based on the previous row. Obviously the last entry for each subject should be a NA.
Which would be the best way to accomplished that ?
I guess questions like that have been already answered a thousand times, so I apologize for
2012 Aug 31
2
Conditional merging in R & if then statement
1)I am wandering how the following SQL statement can be written in R language
w/o using sqldf:
create table detail2 as
select a.*
from detail a,
pdetail b
where a.TDATE=b.TDATE
and (a.STIM >= b.STIM and a.STIM <=b.MAXTIM)
2) when try if then in R it only applies to the 1st row & not to whole
dataset like in SAS. How do you get round that?
in SAS:
data summary;
set all1;