我想比较两个分别来自data.frame
和df1
的{{1}}中的元素。我想从他们那里构建一个名为df2
的新data.frame
。如果元素相等,则out
中的元素为out
,否则为1
。
0
set.seed(1)
df1 <- data.frame(Q1 = sample(letters[1:5], 2, replace = TRUE),
Q2 = sample(letters[1:5], 2, replace = TRUE))
set.seed(2)
df2 <- data.frame(Q1 = sample(letters[1:5], 2, replace = TRUE),
Q2 = sample(letters[1:5], 2, replace = TRUE))
答案 0 :(得分:2)
如果在创建$(document).ready(function(){
$("#submit-trial").click(function(event){
let cmpn = $("#company").val();
let eml = $("#email").val();
let phn = $("#phone").val();
let nt = $("#note").val();
let prsn = $("#person").val();
$.post("/trial-submission", {
company: cmpn,
person: prsn,
phone: phn,
email: eml,
note: nt
})
.done(function(){
$("#company").val("");
$("#email").val("");
$("#phone").val("");
$("#note").val("");
$("#person").val("");
alert("success");
})
.fail(function(){
alert("error");
})
.always(function(){
alert("finished");
});
});
});
-app.post("/trial-submission", function(req, res){
const data = req.body;
let transporter = nodemailer.createTransport({
service: "mail",
auth: {
user: "send@mail.com",
pass: "password"
}
});
let mailOptions = {
from:'send@mail.com',
to:'receive@mail.com',
subject: 'testing',
html:`
Company: ${data.company}<br>
Contact person: ${data.person}<br>
Phone: ${data.phone}<br>
E-mail: ${data.email}<br>
Note: ${data.note}
`
};
transporter.sendMail(mailOptions, function(err, data){
if(err){
console.log('Error Occurs', err);
} else {
console.log('Email Sent!');
}
});
});
的同时使用stringsAsFactors = FALSE
创建数据集,则会造成困难,因为属性会带来比较困难)
data.frame
或者如果是factor
,则用+(df1 == df2)
转换为factor
列
character
或利用type.convert
hack方式更改为+(type.convert(df1, as.is = TRUE) == type.convert(df2, as.is = TRUE))
matrix