All Questions
Tagged with r if-statement
4,580
questions
0
votes
3
answers
52
views
If ... else : the condition has length > 1
I am trying to classify variants according to their type (polymorphisms, insertion or deletion). Here is a snippet of my input :
A T
G C
T AG
C T
TT C
AT CC
Here is the dput output, if you need ...
0
votes
1
answer
42
views
Recoding of item files with if-loop in R [closed]
I´m a uni student who recently started learning to use statistical analysis code with R.
Unfortunately I´m not the best yet, and my prof. isn´t really willing to help. Which is why I´m hoping that ...
2
votes
2
answers
38
views
How do I use an error as input for to if clause (in R)
This workflow will either produce a value or an error. I want that, in the event of an error, will perform an arbitrary code (it could print a message to the console, create an objet).
a <- 1
b <...
0
votes
3
answers
66
views
nested ifelse in R with "condition has length > 1" warning
I have the below data frame and would like to impose some rules to generate new values:
column_1<-c("B","B","B","B","A","A","A",...
0
votes
1
answer
32
views
Multi-Column Conditional Highlighting with KableExtra and ifelse statement
Solution Below
Original Question: I am attempting to highlight the text of a KableExtra table to indicate where group observations increase or decrease by year. However, I am receiving an error about ...
0
votes
2
answers
47
views
use group_by function with if/then/else condition
I have a dateframe like this one with variables corresponding to death on inclusion and variables corresponding to death on follow-up visits:
Id
death_inclusion
date_death_inc
follow-up
...
1
vote
2
answers
56
views
Calculate Beginning and Ending Balances Using R
I am trying to follow a process where I make a contribution to an investment every period, that investment grows or shrinks over time and then I have an ending balance. The next period I take that ...
0
votes
1
answer
63
views
issue with mutate and if's in R 4.4.0 [duplicate]
I updated R to it's new version 4.4.0 and I'm finding errors which I didn't had
for example, this used to work:
temp <- data.frame("a"=c(1,2),"b"=c(3,4),"c"=0)
temp &...
2
votes
2
answers
78
views
How can I convert R tibble character variable (with both characters and integers) to integer type with integers and NA_integer_?
I have a set of data frames with a variable age. In some data frames, age is numeric type (containing integer age values, and -1 and 99 as missing values). In others, it is character type (containing ...
0
votes
2
answers
45
views
How to reassign values based on grouping and dates (R)
I have a dataframe that looks like the following:
grp1 <- c('A','A','A','A','A','A',
'B','B','B','B','B','B',
'C','C','C','C','C','C')
grp2 <- c('PQ2','PQ2','PQ2','PQ2','PQ2',...
0
votes
1
answer
67
views
R Setting up an if statement inside a for loop
I am extremely new to learning coding so please be patient with me.
I have a list made up of two data frames and I need to add a value into a new column col3 based on another column col1. I apologize ...
2
votes
2
answers
63
views
for loop and if else [closed]
df_test2 <- data.frame(test1=c("in", "out"), test2=c(1:2))
> df_test2
test1 test2
1 in 1
2 out 2
for (i in df_test2$test1) {
for (j in df_test2$test2) {
...
2
votes
4
answers
81
views
How to apply multiple conditions when using %in%?
I have this example where I wish to create the column m where if x1 or x2 or x3 = "A" or "B" then m = 1, otherwise m = 0
df <- data.frame(x1 = LETTERS[1:10], x2 = LETTERS[2:11], ...
0
votes
1
answer
27
views
ggplot - Using ifelse inside aes with geom_line gives unlogic result
I am trying to create a chart with two data dependent line formats: the "x opp"-data (high values) with a solid line, and the "x ned"-data (low values) with a longdashed line.
...
1
vote
4
answers
49
views
R - assigning value to a new variable based on the results of the ifelse function
I have some agarose gel band migration data and I would like to automatize the process in terms of assigning values from control lanes to the treatemnt lanes. The data that I get out of the band ...