R:单列CSV输入到多列数据帧(某些可选)

时间:2016-09-24 10:08:30

标签: r csv dataframe missing-data

我有一个19列数据框,有4个可选列,输入来自包含最多40条记录的单列csv文件。如何逐行检查输入并根据需要分流输入行以允许缺少列?

colnames(phoneticsDF) <- c(
   "Alpha",
   "Bravo" ,
   "Charlie",  # optional
   "Delta",    
   "Echo",     # optional: If Delta begins "A:" then Charlie and Echo missing, shunt input ,add NAs.
   "Foxtrot",
   "Golf",
   "Hotel",
   "India",
   "Juliet",
   "Kilo",
   "Lima",
   "Mike",
   "November",
   "Oscar",
   "Papa",
   "Quebec",   # optional: If Kilo equals "B:" then Quebec missing, shunt input, add NA.
   "Romeo",    # optional: If Romeo contains "-" then Romeo missing, set Sierra = Romeo, shunt input, add NA.
   "Sierra"
)

显而易见的复杂情况是,如果我一次读取19行并且任何记录都缺少数据,那么它将包含16-19行中下一条记录的开头?

请指教?

0 个答案:

没有答案