I want to exclude condition C based on the number of condition A and condition B.

Asked 1 years ago, Updated 1 years ago, 319 views

I'm a beginner.

In the analysis of R, I would like to write a program that excludes condition C based on the numbers of condition A and condition B, but it does not work.

(Example)
Sample=c("A", "A", "A", "B", "B")
Day=c(0,1,2,0,1,2)
Value=c(100, 150, 200, 1000, 1050, 1100) testDF=data.frame(Sample,Day,Value)
testDF

I would like to divide the values of Sample A and B by the values of Day 0 in the data frame like above, and get a new column of Norm_value.
N If you get the column Norm_value=c(1,1.5,2,1,1.05,1.1), it will be OK

I thought about using Mutate function, ifelse, but I would appreciate it if you could let me know the know-how as the two conditions do not diverge well.I look forward to your kind cooperation.

r tidyverse

2023-01-29 04:36

1 Answers

>library(tidyverse)
>testDF%>%group_by(Sample)%>%mute(Norm_value=Value/Value [Day==0])

# Atible—4 x 6
# Groups—Sample [2]
  Sample Day Value Norm_value
  <chr><dbl><dbl>
1 A 0 100 1   
2 A 1150 1.5 
3 A2 200 2   
4B 0 10001   
5B 1 1050 1.05
6B 21100 1.1 


2023-01-29 23:15

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.