Displaying 20 results from an estimated 20000 matches similar to: "nested if else statements"
2011 Apr 14
1
integer and floating-point storage
I note that "current implementations of R use 32-bit integers for integer
vectors," but I am working with large arrays that contain integers from 0
to 3, so they could be stored as unsigned 8-bit integers. Can R do this?
(FYI -- This is for storing minor-allele counts for genetic studies.
There are 0, 1 or 2 minor alleles and 3 would represent missing.)
It is theoretically possible
2013 Jul 02
2
Recoding variables based on reference values in data frame
I'm new to R (previously used SAS primarily) and I have a genetics data
frame consisting of genotypes for each of 300+ subjects (ID1, ID2, ID3,
...) at 3000+ genetic locations (SNP1, SNP2, SNP3...). A small subset of
the data is shown below:
SNP_ID SNP1 SNP2 SNP3 SNP4 Maj_Allele C G C A Min_Allele T A T G ID1
CC GG CT AA ID2 CC GG CC AA ID3 CC GG
nc
AA
2023 Dec 18
3
Function with large nested list
Hello list,
I want to make a large rulebased algorithm, to provide decision support for drug prescriptions. I have defined the algorithm in a function, with a for loop and many if statements. The structure should be as follows:
1. Iterate over a list of drug names. For each drug:
2. Get some drug related data (external dataset). Row of a dataframe.
3. Check if adaptions should be made to
2006 Dec 05
5
if(){} else{}
Dear R-community,
my data set looks like 'mat' below.
Plant<-c(NA,1,1,1,NA,NA,NA,NA,NA,1);
Value1<-rnorm(1:10);
Value2<-rnorm(1:10);
mat<-cbind(Plant,Value1,Value2);
I receive data from two different sites.
One site is identified by an interger number, the other site has no data in
column Plant=NA.
My pb:
I'm trying to assign labels "A" or "B" to
2010 Sep 20
2
interpreting one-way anova tables
Hi, I am trying to reconcile anova table in R (summary(lm)) with individual t.test.
datafilename="http://personality-project.org/R/datasets/R.appendix1.data"
data.ex1=read.table(datafilename,header=T) #read the data into a table
summary(lm(Alertness~Dosage,data=data.ex1))
gives:
Call:
lm(formula = Alertness ~ Dosage, data = data.ex1)
Residuals:
Min 1Q Median 3Q Max
2005 Jan 11
1
Nested ifelse - is there a better way?
Dear r-help,
I'm interested in finding a better way to add a column to a data frame
when calculating the new column requires more than one conditional.
For example, if I wanted to associate a character string in
{"Pos","Neg","Zero"} with each number in the following data frame:
> d <- data.frame(num = -2:2)
> d
num
1 -2
2 -1
3 0
4 1
5 2
I
2009 Jun 14
2
How to fix my nested conditional IF ELSE code?
Hi,
I've been struggling most of the morning with an IF ELSE problem, and I
wonder if someone might be able to sort me out.
Here's what I need to do (dummy example, my data are more complicated):
If type = A or B or C
and status = a then count = 1
and status = b then count = 2
and status = c then count = 3
Else if type = D or E or F
and status = a then count = 9
2006 May 17
1
Example Syntax for if - then- and - else Statements
Hello R users,
I am a fairly new R user, however, one of the problems I am having is
the use of applying if-, and-, then-, else- statements in R against
datasets & dataframe. Rtips mentions it, but without simple examples I
am not quite sure what my syntax should look like. I am particularly
interested in syntax that can be used with the transform function. for
example
if foo[,1] ==
2011 Apr 16
3
if else statements in data frame
Dear R experts, I have again a problem. Let I have a data frame like below:
x y
----------
A A
A B
B B
A B
where x and y are the column names. I want to create a new column z where it
is elements
will be like that, if at each row has there at least one 'B', then z will
have value of B, if not then Z will
have missing value(NA) for the corresponding row. So my result data frame
should be
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
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
2009 Jun 23
2
Problem with ifelse statement
Hi R-helpers,
I am trying to use this ifelse statement to recode a variable:
> data$SOCIAL_STATUS<-ifelse(data$SOCIAL_STATUS=="B" & data$MALE>4, "C", "B")
(i.e., if social status is B and there are more than 4 males, then
recode social status to C; otherwise, leave it B)
But, it's not working. See the below R output. Notice that there were
71
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
2012 Aug 13
4
if else elseif for data frames
Hi all,
It seems like I cannot use normal 'if' for data frames. What would be the
best way to do the following.
if data$col1='high'
data$col2='H'
else if data$col1='Neutral'
data$col2='N'
else if data$col='low'
data$col2='L'
else
#chuch a warning?
Note that col2 was not an existing column and was newly assigned for this
2003 Sep 04
1
Allelic Differentiation, sampling, unique(), duplicated()
Hi people,
I have made some progress trying to work out how to solve this problem
but I have got a bit stuck - sorry if this turns out to be a simple
exercise . .
Allelic Differentiation (AD) in genetics measures the number of
different alleles between (say) two populations eg:
Organisms in Pop 1 have alleles: a, b, c, d, e
Organisms in Pop 2 have alleles: b, b, c, d, e
Different
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 <-
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
2010 Jan 14
5
Better way than an ifelse statement?
Hello All,
I am trying to create a column of weights based off of factor levels
from another column. I am using the weights to calculate L scores.
Here is an example where the first column are scores, the second is my
"factor" and the third I want to be a column of weights. I can do
what I want with an ifelse statement (see below), but I am wondering
if anyone knows of a cleaner way
2008 Feb 25
3
Logical statements and subseting data...
Hi,
I'm scratching my head as to why I can't use the subset() command to
remove one line of data from a data frame.
There is just one row (out of 45840) that I'd like to remove and it
can be identified using....
> dim(raw.all.clean)
[1] 45840 10
> subset(raw.all.clean, Height.1 == 0 & Height.2 == 0)
Sample.Name Well SNP Allele.1 Allele.2 Size.1 Size.2
2003 Jun 30
3
if else statements in R
Hi, there
I am a grad student struggling to get my syntax right in a model I am
building in R.
I am trying to specify a variable,W, in a loop, such that on the first
iteration, it is equal to Wo, my starting value, which I have already
specified with
Wo<-9.2
On any other iteration other than the first, I want W to equal the
previous value of W in the iteration. plus an increment from