I am creating a dataframe with 3 columns (char, char, int) called Alleles_df from df1 and df2 using:
Alleles_df <- data.frame('refsnp_id'=character(),'allele'=character(),
'chrom_start' = integer(),stringsAsFactors = F)
for (i in 1:nrow(df1)){
Alleles_df[i,] <- df1[i,][(df1$col1[i]==df2$col1[i]),]
}
for some values of i, I receive the following error:
Error in x[[jj]][iseq] <- vjj : replacement has length zero
This is because the the columns df1 and df2 do not match for certain values of i. How do I bind a row with c("NA","NA",0)
in those situations? I would greatly appreciate your assistance!
df1 is data from an online server called biomart. df2 is what I generated manually. Each has 3 columns with Chromosome, Allele, BaseLocation.
refsnp_id allele chrom_start
1 rs778598915 G/A/T 42693910
2 rs11541159 T/C 42693843
3 rs397514502 G/C 42693321
4 rs762949801 C/T 42693665
5 rs776304817 G/A/T 42693653