下一步在这里尝试:
我得到了一个data.frame
,具有500万行和称为“到达时间”的列,其格式如下:
"11:30:00"
"12:30:00"
"13:30:00"
以此类推。
在data.frame
中的某些地方,它包含类似这样的错误条目:
"111:4:00"
两者的长度相同(8)。如何快速删除这些错误条目? 我猜它必须寻找某种类型的字符串,只允许它:
[0-2][0-9]:[0-5][0-9]:[0-5][0-9]
请帮助!
答案 0 :(得分:0)
您可以使用mod1<-lmer(value~Factor1*Factor2+(1|subject), df)
Anova(mod1)
summary(mod1)
emmeans(mod1, pairwise~Factor1*Factor2)
删除错误的条目:
strptime
输出:
# Sample data.frame
df <- data.frame(
Date=c("11:30:00",
"12:30:00",
"13:30:00",
"111:4:00")
)
# Remove the entries which are not following the date format
df[is.na(strptime(df$Date,format="%H:%M:%S")),]
答案 1 :(得分:0)
我们可以使用<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
<style>
/* Style the button that is used to open and close the collapsible content */
.collapsible {
background-color: #eee;
color: #444;
cursor: pointer;
padding: 18px;
width: 100%;
border: none;
text-align: left;
outline: none;
font-size: 15px;
}
/* Add a background color to the button if it is clicked on (add the .active class with JS), and when you move the mouse over it (hover) */
.active, .collapsible:hover {
background-color: #ccc;
}
/* Style the collapsible content. Note: hidden by default */
.content {
padding: 0 18px;
display: none;
overflow: hidden;
background-color: #f1f1f1;
}
</style>
</head>
<body>
<button class="collapsible">Open Collapsible</button>
<div class="content">
!--- YOUR HTML CODE HERE ---!
</div>
<script>
var coll = document.getElementsByClassName("collapsible");
var i;
for (i = 0; i < coll.length; i++) {
coll[i].addEventListener("click", function() {
this.classList.toggle("active");
var content = this.nextElementSibling;
if (content.style.display === "block") {
content.style.display = "none";
} else {
content.style.display = "block";
}
});
}
</script>
</body>
</html>
grep
或者另一个选择是grep("^[0-9]{2}:[0-9]{2}:[0-9]{2}$", vec, value = TRUE)
#[1] "11:30:00" "12:30:00" "13:30:00"
中的times
chron
library(chron)
vec[!is.na(times(vec))]
#[1] "11:30:00" "12:30:00" "13:30:00"