我有300个位置,比方说“A1,A2,A3,...,A300”,我有40个值。我的位置在df1中,我的值在df2中。我想将这40个值添加到每个位置,位置A1将具有从40到40的代码,依此类推。
我试图制作一个for循环:
df1 <- c("A1", "A2", "A3")
df1 <- data.frame(df1)
colnames(df1) <- c("location")
df2 <- c(1:40)
df2 <-data.frame(df2)
colnames(df2) <- c("code")
data <- data.frame() #Empty data.frame
for (i in df2) {
temp <- df1
temp$code <- rep(i)
data1 <- rbind(data, temp)
}
此脚本导致错误:'替换有40行,数据有315'。
有人可以告诉我该怎么做才能使这项工作?
期望的输出:
答案 0 :(得分:1)
我们可以使用using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
const string sec = "ProEMLh5e_qnzdNUQrqdHPgp";
const string sec1 = "ProEMLh5e_qnzdNU";
var securityKey = new SymmetricSecurityKey(Encoding.Default.GetBytes(sec));
var securityKey1 = new SymmetricSecurityKey(Encoding.Default.GetBytes(sec1));
// This is the input JWT which we want to validate.
string tokenString = string.Empty;
// If we retrieve the token without decrypting the claims, we won't get any claims
// DO not use this jwt variable
var jwt = new JwtSecurityToken(tokenString);
// Verification
var tokenValidationParameters = new TokenValidationParameters()
{
ValidAudiences = new string[]
{
"536481524875-glk7nibpj1q9c4184d4n3gittrt8q3mn.apps.googleusercontent.com"
},
ValidIssuers = new string[]
{
"https://accounts.google.com"
},
IssuerSigningKey = securityKey,
// This is the decryption key
TokenDecryptionKey = securityKey1
};
SecurityToken validatedToken;
var handler = new JwtSecurityTokenHandler();
handler.ValidateToken(tokenString, tokenValidationParameters, out validatedToken);
aggregate
如果值位于不同的数据集中且与原始数据集中的顺序相同,则只需执行aggregate(Value ~Location, df1, sum)
和cbind
aggregate
假设每个数据集中没有公共列到aggregate(Value ~Location, cbind(df1, df2), sum)
基于OP的更新
merge
expand.grid(location = df1$location, code = df2$code)
来自CJ
data.table