我想在函数中使用下面的行
datehit <- vector(mode="Date",length(vectordiagdate))
但我收到错误
> Error in vector(mode = "Date", length(vectordiagdate)) :
vector: cannot make a vector of mode 'Date'.
稍后我将使用datediff
。
有什么问题,是否有解决方法?
答案 0 :(得分:1)
没有Date
的存储模式。
日期是class
:
date.vec <- seq(Sys.Date(), Sys.Date()+10, 1) # date vector example
mydate <- as.Date("1970-01-01") # class conversion from character to date
使用你的例子(松散地):
as.vector(data.frame(x = seq(Sys.Date(),Sys.Date()+10,1)), mode = "list")
x 1 2016-07-11 2 2016-07-12 3 2016-07-13 4 2016-07-14 5 2016-07-15 6 2016-07-16 7 2016-07-17 8 2016-07-18 9 2016-07-19 10 2016-07-20 11 2016-07-21
datehit <- as.Date(datehit$x)
有效的存储模式是:
答案 1 :(得分:0)
如果你想要一个类似于经常使用function onDocumentMouseDown( e ) {
if(document.activeElement.id != "myThreeJSElementID"){
//some other element has been clicked so let's return with nothing:
return;
}
e.preventDefault();
console.log(dialog);
var mouseVector = new THREE.Vector3();
mouseVector.x = 2 * (e.clientX / window.innerWidth ) - 1;
mouseVector.y = 1 - 2 * ( e.clientY / window.innerHeight );
var raycaster = new THREE.Raycaster();
raycaster.setFromCamera( mouseVector, camera );
var intersects = raycaster.intersectObjects(objectCollection );
if (intersects.length > 0) {
var selectedObject = intersects[0];
console.log("Intersected object", intersects[0]);
selectedObject.object.material = (selectedObject.object.material.wireframe) ? selectedBoxMaterial : unselectedBoxMaterial;
var text = intersects[0].distance;
var title = "Shelf info";
if (dialog == false) {
createDialog(title, text, offset);
offset = offset - 50;
console.log(offset);
dialog = true;
console.log(dialog);
}
if (dialog == true) {
{jQuery("#bodyText").text(text);
}
}
}
的东西,作为一个模板对象来填写,那么你可以做
vector()
我们无法使用as.Date(rep(NA, length = 10))
> (foo <- as.Date(rep(NA, length = 10)))
[1] NA NA NA NA NA NA NA NA NA NA
> class(foo)
[1] "Date"
作为NULL
的对象,因为它会在rep
上发出警告以惹恼我们as.Date
窒息。