我一直试图在r中将数据帧保存为csv格式。它具有22种具有各种格式的变量。正在寻找一种在csv中保存文件的解决方案。
<?php
if($dataNilai!=""){
foreach($dataNilai as $isi){
$no++;
if($no%2 ==0){
$tbclass = "alt";
$tbnoclass = "noalt";
}else{
$tbclass = "";
$tbnoclass = "no";
}
?>
<tr>
<th scope="row" class="<?php echo $tbnoclass ?>"><?php echo $no ?>.</th>
<td class="<?php echo $tbclass ?>"><?php echo $isi['nim'] ?></td>
<td class="<?php echo $tbclass ?>"><?php echo $isi['nama'] ?></td>
<td align="center" class="<?php echo $tbclass ?>"><select name="nilai[<?php echo $isi['id_khs'] ?>]">
<option value="Hadir" <?php if($isi['ke_1']=="Hadir") echo "selected=\"selected\""; ?>>Hadir</option>
<option value="Izin" <?php if($isi['ke_1']=="Izin") echo "selected=\"selected\""; ?>>Izin</option>
<option value="Sakit" <?php if($isi['ke_1']=="Sakit") echo "selected=\"selected\""; ?>>Sakit</option>
<option value="Absen" <?php if($isi['ke_1']=="Absen") echo "selected=\"selected\""; ?>>Absen</option>
</select>
</td>
<td align="center" class="<?php echo $tbclass ?>"><select name="nilai[<?php echo $isi['id_khs'] ?>]">
<option value="Hadir" <?php if($isi['ke_2']=="Hadir") echo "selected=\"selected\""; ?>>Hadir</option>
<option value="Izin" <?php if($isi['ke_2']=="Izin") echo "selected=\"selected\""; ?>>Izin</option>
<option value="Sakit" <?php if($isi['ke_2']=="Sakit") echo "selected=\"selected\""; ?>>Sakit</option>
<option value="Absen" <?php if($isi['ke_2']=="Absen") echo "selected=\"selected\""; ?>>Absen</option>
</select>
write.table(newdata,file =“ MyDataNew.csv”,col.names = NA,错误: EncodeElement中未实现的类型“列表”
我希望文件以csv格式保存。
答案 0 :(得分:0)
此问题可能通过以下方式解决:
write.csv(as.data.frame(newdata),file = "MyDataNew.csv")