All Questions
Tagged with r if-statement
4,601 questions
4
votes
4
answers
177
views
How to do multiple if/else logic calculations and apply them to several columns in a dataframe?
Suppose I have a dataframe df in R like this:
A B C D
1.4 4.0 6.0 1.0
2.5 1.5 2.4 2.3
3.0 1.7 2.5 3.4
Say I want to write a function that checks the value of each cell ...
1
vote
1
answer
40
views
Extracting an outcome or string from a 'frtest' object (FRAIR package in R)
I'm trying to run a simulation experiment using simulated functional response data. My goal is to use frair_test from the FRAIR package to test for type-II versus type-III functional responses within ...
0
votes
1
answer
50
views
R how to recreate new columns based on an if statement [duplicate]
I have a long column that contains the results of selected items separated by commas within the same cell. I want to create new columns based on conditions.
example
favorite_fruits <- c("...
2
votes
4
answers
84
views
how to populate column based on multiple types of strings in other column
I have a data set of behavioral data. I want to assign all the different behaviors as "aggressive", "submissive", "affiliative", or leave blank in a column of the data ...
3
votes
3
answers
63
views
Cumulative sum in R if value greater than 0
I want to create a new column with a running sum of every value greater than 0. I have a dataframe:
df=data.frame(year=c('2007-04-01','2007-04-02','2007-04-03','2007-04-04','2007-04-05','2007-04-06'),...
1
vote
4
answers
97
views
How to transform whole dataframe using ifelse in R [duplicate]
I have a dataset with multiple samples (rows) and features present in the samples (columns). Each feature has a numeric value between 0 and 1 for each sample. I want to turn this into presence/absence ...
1
vote
2
answers
81
views
Error in ifelse Comparison for R language [closed]
I am new to R and trying to apply my limited knowledge to a real world situation but it is frustrating me to no end and would appreciate some assistance.
I have a data frame with Id that is a double, ...
0
votes
1
answer
102
views
Nested If Statements in R for Increasing Numbers Rounding [closed]
I have a large dynamic set of data that spans over 20 years. I need to create a function that will round correctly to 3 significant figures from numbers as small as 0.000600 to as large as 999. I have ...
2
votes
3
answers
83
views
R: Conditional suppression of values across multiple rows
This question is similar to this question, but the difference in this case is to suppress data row-wise. The suppression is done in each row by replacing any value less than 6 in each row with -1 ...
2
votes
4
answers
101
views
R: Conditional suppression of values across multiple columns
I have a huge data. I like to suppress data across multiple columns by replacing any value less than 6 in each column with -1 such that if in a column, there is only one suppressed value, I want to ...
0
votes
0
answers
43
views
html_element() in rvest: How to check if a url has a certain element
I am trying to webscrape some addresses from urls and I am not sure if I am correctly making the variable that contains the specific element I want to check the url has :
addressParser <- function(...
0
votes
1
answer
38
views
Assign value to all rows based on condition being fulfilled or not
I have a table with different columns that include the ID, Year of observation and the value observed. For simplicity, the following is a small sample that conveys my problem:
df = data.frame(
ID=c(1,...
0
votes
0
answers
73
views
Use of "else if" to alternate between lists
I am trying to create a rhandsontable with variables Col1 and Col2.
Col1 has factor levels = c("A", "B").
Col2 has two alternating factor levels = c("a1", "a2") ...
1
vote
3
answers
152
views
How can I convert a list to numerical in r?
I am using the following data and have come across a roadblock.
I used read.csv to import my raw data into r.
# from OHP$ohp17.value
list(NULL, NULL, "19.9 nmol/L", "0.7 nmol/L", ...
1
vote
1
answer
29
views
How to sum up checkboxgroupinput objects in R shiny?
Given is a checkbox in an R Shiny app. The shown choices represent numeric values. If one or more choices are selected the numeric values should be summed up to the end result.
If checkbox choices ...