Home > OS >  Create a new column by match conditional in two columns in pairwise dataframe in R
Create a new column by match conditional in two columns in pairwise dataframe in R

Time:08-25

I am trying to create a new column by conditionals in the matching of two columns with the same factors, in order to summarise the data.

This is how looks the dataframe

enter image description here

This is how I want to summarise

enter image description here

This is my proposed not working code:

probe$Cluster<-"cluster"
for (i in 1:length(probe)){
if(is.na(probe[i,4])){
probe[i,9]<-probe[i,6]}
if(is.na(probe[i,6])){
probe[i,9]<-probe[i,4]}
if(identical(probe[i,4],probe[i,6])){
probe[i,9]<-probe[i,4]}}
if(!identical(probe[i,4],probe[i,6])){
probe[i,9]<-probe[i,4]
rep(probe[i,1:9]%>%probe[i,9]<-probe[i,6}
#Then create a summary of this like this:
Sum<-probe%>%group_by(Method,Cluster)%>% summarise(mean(relation, na.rm 
=FALSE),numberobservations=length(unique(GenA)))%>           
  • Related