以下是基于我的一小部分数据的示例:
NAME <- c("SYNOP", "SYNOP", "METAR", "METAR", "SYNOP", "METAR")
AIR <- c(6.7, 8.3, 9.2, 8.9, 9.1, 8.7)
Example <- data.frame(NAME, AIR)
NAME AIR
1 SYNOP 6.7
2 SYNOP 8.3
3 METAR 9.2
4 METAR 8.9
5 SYNOP 9.1
6 METAR 8.7
我正在使用grep来选择这个数据的子集,其中NAME == METAR并找出出现次数:
ex_METAR <- Example[grep("METAR", Example$NAME), ]
nrow(ex_METAR)
我必须为NAME
的大量实例重复此操作,并希望通过在函数中使用它来加快此过程。但是,每次收到错误消息时我都必须做错事:
example_Function <- function (A, B, C) {
A[grep("B", A$C), ]
}
> example_Function(Example, "METAR", Example$NAME)
[1] NAME AIR
<0 rows> (or 0-length row.names)
我原以为是我在描述“METAR”,所以我尝试了只有A和C的函数并得到了同样的错误。
example_Function <- function (A, C) {
A[grep("METAR", A$C), ]
}
example_Function(Example, Example$NAME)
有没有我正在做错的事情或者这只是不起作用?我以前从未试图以这种方式改编功能。或者一个功能可能是错误的方式?!提前谢谢。
(不是Aggregate a dataframe on a given column and display another column的副本,它正在寻找带有最大值的子集。我需要对列中的单词进行子集化,并知道发生了多少次。)
答案 0 :(得分:1)
我认为这就是你要找的东西:
<?php
include('include/config.php');
include('parts/header.php');
$submit = $_POST['submit'];
$username = (int)$_POST['username'];
$password =(int)$_POST['password'];
if ($submit) {
if(!empty($username OR !empty($password))) {
$sqlQuery="SELECT * FROM users WHERE user_login = '$username' AND password = '$password'";
//SELECT * FROM `wp_users` WHERE `user_login`='1' OR '1' = '1' AND `user_pass`='1' OR '1' = '1'
//$sqlQuery = mysql_query("SELECT * FROM users WHERE username = '$username' AND password = '$password'");
echo $sqlQuery;
exit;
if(mysql_num_rows($sqlQuery) == 1) {
// Success - admin'#
echo "LOGGEDIN";
$_SESSION['loggedin'] = 1;
} else {
echo "Wrong password or username";
}
} else {
echo "You didn't fill every field.";
}
}
?>
<div id="container">
<form method="POST">
<input type="text" name="username" placeholder="Indtast brugernavn..">
<input type="password" name="password" placeholder="Indtast kodeord..">
<input type="submit" name="submit" value="Log ind">
</form>
</div>
输出:
SELECT * FROM wp_users WHERE user_login = '7' AND user_pass = '7'