Learn More →
Learn More →
Learn More →
getwd()
setwd("C:\\Users\\user\\Desktop")
getwd()
# setting
output_file <- "output.csv"
# import csv
library(dplyr)
library(tidylog)
class <- read.csv("class.csv",fileEncoding = "UTF-8-BOM")
class
attendence <- read.csv("today.csv",fileEncoding = "UTF-8-BOM")
attendence
# compare
abscence <- anti_join(class,attendence)
abscence
abscence <- abscence %>% mutate(attendence = "x")
new_class <- left_join(class,abscence)
new_class
# turn <NA> into "o"
new_class$attendence[is.na(new_class$attendence)]<- "o"
new_class
# output csv
write.csv(new_class,file= output_file,row.names = FALSE)
data
注意: 出席名單的排序方式不一定與修課名單相同
Learn More →
成果
Learn More →
fileEncoding = "UTF-8-BOM"
這邊read.csv加上這行是為了不要出現亂碼
有時候直接read 可以,但有時候不行
anti_join(class,attendence)
left_join(class,abscence)
這邊詳情可以參考這裡
簡單說,anti = 找不同 = 找缺席
left join 則是以class的row為主,跟abscence合併
合併後,缺席的人會有x,但是因為出席的人attendence那欄沒有賦值
所以是NA
new_class$attendence[is.na(new_class$attendence)]<- "o"
原本這邊我是想用for寫,但是R的for好像不接受NA
所以改用這種找出NA值然後接改的方式
小結
也不知道這樣寫484比較快的寫法
但是現階段看來還行,行數也不多
R
beginner
cat
tutorial
25歲職場新鮮人的求職面試之路
Mar 15, 2024修課
Aug 11, 2023SQL語法學習心得 第四篇(JOIN) 線上SQL測試網站 3 table JOIN id and matchid is the join index of two table
Aug 3, 2022R tm + wordcloud text mining :::warning 如果無法轉成DocumentTermMatrix ---> Rcpp didn't have previous_save 之類的error 把Rcpp整個檔案刪掉 再 install.packages("Rcpp") :::
Mar 29, 2022or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up