我正在尝试使用下面的代码复制我的数据框中的行。但是,我发现它很慢。
duprow = df[1,]
for(i in 1:2000)
{
print(i)
df = rbind(df,duprow)
}
Run Code Online (Sandbox Code Playgroud)
有没有更快的方法?
我没有任何Java经验并且具有C背景.
我想创建一个新的数据类型,如抽象数据类型.在C中,这将通过为新数据类型创建结构来完成; 我理解在Java中,您为该新数据类型创建一个类,然后继续为该类创建对象.
我写了两种不同的方式,它们似乎都有效.但我不明白第二种方式的缺点.
在这里,我为数据类型创建一个类,创建它的一个实例,然后执行操作.我发现这是互联网教程中使用的设计.
public class DesignOne {
public static void main(String[] args) {
MyDataType obj = new MyDataType(3,4);
System.out.println(obj.sum());
}
}
class MyDataType {
int i;
int j;
MyDataType(int i, int j) {
this.i = i;
this.j = j;
}
int sum() {
return this.i + this.j;
}
}
Run Code Online (Sandbox Code Playgroud)在这里,我在同一个类中创建了一个类的实例,我有我的驱动函数.类似sum的操作也被定义为类的成员.基本上,只有一个班级.
public class DesignTwo {
int i;
int j;
DesignTwo(int i, int j) {
this.i = i;
this.j = j;
}
int sum() {
return this.i + …Run Code Online (Sandbox Code Playgroud)我正在尝试使用分类属性对R进行线性回归,并观察到我没有得到每个不同因子水平的系数值.
请参阅下面的代码,我有状态的5个因子级别,但只能看到4个系数值.
> states = c("WA","TE","GE","LA","SF")
> population = c(0.5,0.2,0.6,0.7,0.9)
> df = data.frame(states,population)
> df
states population
1 WA 0.5
2 TE 0.2
3 GE 0.6
4 LA 0.7
5 SF 0.9
> states=NULL
> population=NULL
> lm(formula=population~states,data=df)
Call:
lm(formula = population ~ states, data = df)
Coefficients:
(Intercept) statesLA statesSF statesTE statesWA
0.6 0.1 0.3 -0.4 -0.1
Run Code Online (Sandbox Code Playgroud)
我还通过执行以下操作尝试使用更大的数据集,但仍然看到相同的行为
for(i in 1:10)
{
df = rbind(df,df)
}
Run Code Online (Sandbox Code Playgroud)
编辑:感谢eipi10,MrFlick和经济的回应.我现在明白其中一个级别被用作参考级别.但是当我得到一个状态值为"GE"的新测试数据时,如何用等式y = m1x1 + m2x2 + ... + c代替?
我也尝试将数据展平,使得每个因子级别都得到它的单独列,但是对于其中一个列,我得到NA作为系数.如果我有一个状态为'WA'的新测试数据,我怎样才能获得'人口价值'?我用什么代替它的系数?
> df1 …Run Code Online (Sandbox Code Playgroud) 我有两个数据帧,第一个包含9994行,第二个包含60431行.我想合并两个数据帧,使合并的数据帧包含两个数据帧的组合列,但只包含9994行.
但是,合并后我获得超过9994行.我怎样才能确保不会发生这种情况?
df1 = readRDS('data1.RDS')
nrow(df1)
# [1] 9994
df2 = readRDS('data2.RDS')
nrow(df2)
# [1] 60431
df = merge(df1,df2,by=c("col1","col2"))
nrow(df)
# [1] 10057
df = merge(df1,df2,by=c("col1","col2"),all.x=TRUE)
nrow(df)
# [1] 10057
nrow(na.omit(df))
# [1] 10057
Run Code Online (Sandbox Code Playgroud)
编辑:遵循akrun的评论.是的,第二个数据框中有重复项
nrow(unique(df2[,c("col1","col2")]))
# [1] 60263
nrow(df2)
# [1] 60431
Run Code Online (Sandbox Code Playgroud)
如果同一{col1,col2}组合有多个,如何从数据框中只取一行.当我合并时,我想只有9994行.
当我从命令行运行我的脚本作为Rscipt myscript.R时,我能够等待R中的用户输入,并从stdin读取输入.
cat("Enter word : ")
word <- readLines(file("stdin"),1)
print(word);
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用下面的代码从终端执行此操作时,它只是转到下一行而不接受用户输入.我该如何克服这个问题?
word <- readline(prompt="Enter a word: ")
print(word);
Run Code Online (Sandbox Code Playgroud) 我有一个关于编译器如何评估c中"AND"条件的问题.
说,我写一个声明就好
if( (today is Thursday) && (Month is July) )
{
//do something
}
Run Code Online (Sandbox Code Playgroud)
假设今天不是星期四,但月份确实是七月.
编译器是否检查两个条件,并执行1&0 == 0?或者,一旦它看到今天不是星期四,它就会跳过,甚至不用费心去查看月份情况,因为它无关紧要.
我正在使用以下gcc
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
Run Code Online (Sandbox Code Playgroud) 下面的代码,链接到jsbin
<html>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r75/three.js"></script>
<script>
// global variables
var renderer;
var scene;
var camera;
var geometry;
var control;
var count = 0;
var animationTracker;
init();
drawSpline();
function init()
{
// create a scene, that will hold all our elements such as objects, cameras and lights.
scene = new THREE.Scene();
// create a camera, which defines where we're looking at.
camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);
// create a render, sets the background color and …Run Code Online (Sandbox Code Playgroud) 我希望获取我作为工件推送到 Azure DevOps 的文件的内容
通过使用此 API,我能够获得带有工件 zip 网址的 json 响应
https://dev.azure.com/uifabric/cd9e4e13-b8db-429a-9c21-499bf1c98639/_apis/build/builds/8838/artifacts?artifactName=drop&api-version=5.0
Run Code Online (Sandbox Code Playgroud)
但是,我真正想要的是bundlesizes.json在此 zip 中调用的文件的内容。
我确实在这里遇到了 Get File API ,它提到了一个 API,如下所示
GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/artifacts?artifactName={artifactName}&fileId={fileId}&fileName={fileName}&api-version=5.0
Run Code Online (Sandbox Code Playgroud)
我尝试按如下方式替换它
https://dev.azure.com/uifabric/fabricpublic/_apis/build/builds/8838/artifacts?artifactName=drop&fileId=bundlesizes.json&fileName=bundlesizes.json&api-version=5.0
Run Code Online (Sandbox Code Playgroud)
我认为我缺少的是fileId字段,我不知道需要输入什么。文档说fileId是文件的主键。但是,我不知道在哪里可以找到它。
azure-devops azure-pipelines-build-task azure-pipelines-release-pipeline azure-artifacts azure-devops-rest-api
我在二叉搜索树中有以下用于插入和删除的java代码.但这是我第一次使用java,并希望在我可以谷歌这些概念之前寻求某些方面的帮助.
public class BinarySearchTree {
public static Node root;
public BinarySearchTree(){
this.root = null;
}
public boolean find(int id){
Node current = root;
while(current!=null){
if(current.data==id){
return true;
}else if(current.data>id){
current = current.left;
}else{
current = current.right;
}
}
return false;
}
public boolean delete(int id){
Node parent = root;
Node current = root;
boolean isLeftChild = false;
while(current.data!=id){
parent = current;
if(current.data>id){
isLeftChild = true;
current = current.left;
}else{
isLeftChild = false;
current = current.right;
}
if(current ==null){
return false; …Run Code Online (Sandbox Code Playgroud) 我明白这是指当前的对象.所以不使用objectname.fun(objectname.nonstaticmember),为什么我不能使用objectname.fun(this.nonstaticmember)
请参考下面的示例,并在最后看到最后两条评论.
public class Question
{
int data;
void myfun(int data)
{
System.out.println("data=="+data);
}
public Question(int data)
{
this.data = data;
// TODO Auto-generated constructor stub
}
public static void main(String[] args)
{
Question question = new Question(10);
//question.myfun(question.data);//WORKS
question.myfun(this.data);//DOES NOT WORK
}
}
Run Code Online (Sandbox Code Playgroud) r ×4
java ×3
dataframe ×2
oop ×2
rstudio ×2
azure-devops ×1
azure-pipelines-release-pipeline ×1
c ×1
constructor ×1
javascript ×1
lm ×1
merge ×1
spline ×1
this ×1
three.js ×1