vendredi 27 mai 2016

Alternative to ifelse in R? Need to use two column in one table to match to a second table and bring output [duplicate]

This question already has an answer here:

I'm new to R so bear with me..

I have one table that looks like this (hundreds of rows long)

Col1 Col2   
1       1
16      6
36      3
5       8
2       26

... ...

My second Table looks likes this (has over 600 rows)

Col1   Col2    Output Column
1       1          849
29      3          348
4       4          584
5      36          373 
36      36        1902

I need to match Col 1 and Col2 in each table so that the combination of unique combination of Col1 and Col2 in table 2 returns the value in the Output column of Table 2.

I know I could spend hours writing a nested ifelse statements but there has to be a more efficient way to do this.

Any help is appreciated, even if you could just provide some stuff to look into.

Is this returning an empty list?

I have this method that is removing elements from a list,

List<LinkedList<Object>> list = new LinkedList<>();

that removes two elements, returns a list which is then put through a queue names=queue.removePair();

public List removePair() {
    List<E> nList = new LinkedList<>();
    if (list.isEmpty() == true) {
        throw new InsufficientElementsException();
    }
    if (list.isEmpty() == false) {
        Object temp;
        for (int i = 0; i < list.size(); i++) {
            temp = list.get(i).size();
            if (temp.equals(2)) {
                nList.add((E) list.get(i));
                list.remove(i);
            }
        }
        return nList;
    }

    return nList;
}

I believe this doesn't work because when I return the Nlist, it's only returning the one declared in the first line? How do I fix this?

sender.tag in no set to 1 if user has Login in keychain?

I have create this logic for login button action.my problem if user has login and set sender.tag to loginButtonTag= 1 it will not run this code in "else if sender.tag == loginButtonTag".

@IBAction func signedInAction(sender: AnyObject)
{

    if (txtfUsername.text == "" || txtfPassword.text == "") {
         alert()
        return;
    }

    txtfUsername.resignFirstResponder()
    txtfPassword.resignFirstResponder()

    if sender.tag == createLoginButtonTag {
        let hasLoginKey = NSUserDefaults.standardUserDefaults().boolForKey("hasLoginKey")
        if hasLoginKey == false {                NSUserDefaults.standardUserDefaults().setValue(self.txtfUsername.text, forKey: "username")
        }


        keychain.set(txtfUsername.text!, forKey:kSecValueData as String)
        NSUserDefaults.standardUserDefaults().setBool(true, forKey: "hasLoginKey")
        NSUserDefaults.standardUserDefaults().synchronize()
        loginButton.tag = 1

        performSegueWithIdentifier("dismissLogin", sender: self)
    }
    else if sender.tag == loginButtonTag
    {
        if checkLogin(txtfUsername.text!, password: txtfPassword.text!)
        {
            performSegueWithIdentifier("dismissLogin", sender: self)
        }
        else
        {
            alert()
        }
    }
}

How to highlight current link in foreach loop

I have a script that lists all the directories as links.

<?php
$dirs = array_filter(glob('../*'), 'is_dir');
?>

<ul style="float:left;">
<?php
foreach ($dirs as $nav) {
    echo "<li><a href='$nav'>".basename($nav)."</a></li>";
}
?>
</ul>

I want to highlight the current directory, or give the current link a class or id. I understand that i need if statement to accomplish this like if(currentLink=thisLink) { // add span class somehow} else {// continue looping} , but I am not completely sure how to do this.

What would be the correct way to implement this ?

(Java) getting values from LinkedList according to user input

Facing some issues with my lab assignment :/ I've done trouble shooting to find that both there's nothing wrong with my filereader/bufferedreaders, Vehicle method and LinkedList values

I'm found out that I'm having Problems getting the if statement to work I do not know How do I compare the current linkedlist data extracted from my file.txt using tokenizer to pass into given fields with userinput using if/else??

public class Lab6 {  

//I've done troubleshooting for my programme, 
    //the only problem that remains is my if/else statement which 
    //I have no idea how to go about doing

    //I'm having Problems getting the if statement to work 
    //How do I compare linkedlist data with userinput using if/else??
final String INPUT_PROMPT = "\nPlease enter the search word " + "that you would like to obtain more information on:";
String tokenizer;
FileReader fr = new FileReader("Vehicle.txt");
BufferedReader br = new BufferedReader(fr);
LinkedList<Vehicle> list = new LinkedList<Vehicle>();
String line;


while (line !=null)
{
  line = br.readline;

     tokenizer = new StringTokenizer(line, ",");
 group = tokenizer.nextToken();
 brand = tokenizer.nextToken();
 model = tokenizer.nextToken();
 rate = Double.parseDouble(tokenizer.nextToken());
Vehicle newVehicle = new Vehicle(group, brand, model, rate);
list.add(newVehicle);

}
System.out.println(INPUT_PROMPT);
try{
BufferedReader ubr = new BufferedReader(new InputStreamReader (System.in));
String uline = ubr.readLine();

for(int i = 0; i< list.size(); i++)
    {
//I'm stuck at the if //it's the only part that doesn't work for my codes
if(list.get(i)== uline.contains(temp))
        {
            //print out the information of the vehicle that match user input
            System.out.println(list.get(i));

        }   
    }
//etc
catch(IOException e)
        {
            System.out.println(e);
        }

        catch (Exception e) 
        {
            System.out.println("Input error!" + e);
        }

}

php best practices for returning multiple lines of content in an IF statement

I am writing a php plugin for wordpress. I'm trying to be mindful of clean coding and want to know the best practice for returning several lines of HTML code in an IF statement.

Obviously I know about echo but I thought I had seen a technique like this used, but it doesn't seem to work for me. The idea being that you create several $content variables and then return it outside of the IF statement.

function signup() {
    if(!Skizzar_Registration::is_skizzar_site_active()) {
        $content = '<div class="signup">';
        $content .= '<h1>Sign up</h1>';
        $content .= '</div>';
    } else {
        $content = '<div class="signed_up">you are already signed up</div>';
    }

    return $content;

}

Currently though this returns nothing when I call the function

jeudi 26 mai 2016

swift: access variable inside else statement

I'm trying to access a variable I'm creating in if statement in else. For example:

if let filePath: NSURL = documentDirectory.URLByAppendingPathComponent("myFile.txt"){

But I can't access to the variable filePath in else block:

enter image description here Any of you knows how can access the variable filePath inside the else block?

I'll really appreciate your help