vendredi 1 novembre 2019

How to delete entire row for x if y appears at least once in same column?

I would like to run a code in which I delete the entire row for entries of "x", if "y" appears at least once in the same column of "var1". I can't find any solution in R. Below is what I tried.

In the code below, I tried to tell R that if var1 contains at least one y, all rows containing x should be filtered out/removed.

 if (all(df$var1 %in% c("y"))) { 
 df <- filter(!var1 %in% c("x"))
 }

Unfortunately the code above doesn't return any change in df, even though y appears several times in var1.

Many thanks. I appreciate any kind of recommendation.

ISNA + Vlookup function not working but vlookup function works before

I set different variable and want to run a formula as follows, however I can run it in excel but cannot run it in vba, attached is for reference. Please notice that all variable are set correctly because i can run a vlookup formula before, but I can't run it after I added if isna function.

    For iStyleD = lrStyleD To 1 Step -1
            If Range(ColLstatus & iStyleD).Value2 = "" Then
                Range(ColLstatus & iStyleD).Value2 = "=IF(ISNA(VLOOKUP(" & ColLstatus & iStyleD & ",'C:\Excel\halo\[abc.xlsx]Details'!R6C4:R210C5,1,FALSE)), ""NO"", ""YES"")"
            End If
    Next iStyleD

How to make .Cells.Value work as one of multiple actions in IF...THEN loop?

I am having a problem with .Cells.Value part of the following code:

   Dim lngLastRow As Long, lngRow As Long
   Dim strColumn As String
   Dim dateColumn As String

   strColumn = Split(Range("aaa").Address, "$")(1)
   dateColumn = Split(Range("bbb").Address, "$")(1)

   With ActiveSheet
      lngLastRow = .Cells(.Rows.Count, strColumn).End(xlUp).Row
      For lngRow = 2 To lngLastRow
         If IsDate(.Cells(lngRow, strColumn).Value) And .Cells(lngRow, strColumn).Value < .Cells(lngRow, dateColumn).Value + 5 Then
            .Rows(lngRow).Interior.Color = RGB(255, 128, 0)
         End If
         If IsDate(.Cells(lngRow, strColumn).Value) And .Cells(lngRow, strColumn).Value = .Cells(lngRow, dateColumn).Value Then
            .Rows(lngRow).Interior.Color = RGB(255, 0, 0)
            Cells(lngRow, 6).Value = "1" 'This line does not execute...
         End If
      Next lngRow
   End With

Cells(1, 7).Value = "2" 'This line is identical to the one in the loop, but executes as it should...

The desired result is that the If...Then function will compare date values of two columns and format the whole row accordingly. However, I also need to have number "1" entered in column 6 if the dates are equal.

I am confused, because the line seems to be working perfectly when it is not in the loop... I will appreciate any guidance. Thanks!

How can contentEquals compare multiple strings with all strings matching?

Good morning, The following java code shall compare three strings with requiredProgram and only execute the if-loop and the do-while-loop if requiredProgram does not equal all three strings. It is instead executing the if-loop and the do-while-loop if only one or two of the strings don't match the requiredProgram. How can I program the code to do what I want it to do?

if (!requiredProgram.contentEquals(program1)||
    !requiredProgram.contentEquals(program2)||
    !requiredProgram.contentEquals(program3)) {
        System.out.println("Ohje, das tut mir leid. Hier muss ein Fehler unterlaufen sein! Bitte versuchen sie es erneut.");

    }
    } while(!requiredProgram.contentEquals(program1)||
            !requiredProgram.contentEquals(program2)||
            !requiredProgram.contentEquals(program3));

How to read an empty string to create output

I have file of which I need to read input. On one of the lines, there is no name added. In this case, I want to print out that no match was found. The problem that I'm having is that I don't know how I can make sure the program actually reads the part as an empty string. What happens now is that the will just leave the line empty on the console.

The date input looks like this:

5=20=22=10=2=0=0=1=0=1;Vincent Appel,Johannes Mondriaan

2=30=15=8=4=3=2=0=0=0;

similarityScoresScanner.useDelimiter(";|,");

    while(similarityScoresScanner.hasNext()) {
        String name = similarityScoresScanner.next();

        if (name.isEmpty()) {
            out.printf("No matches found\n");
        } else {
            out.printf(name, "\n");
        }

    } 

IF/ELSE give wrong result because of "wrong" element found

I'm using Python/Selenium in PyCharm

After step where I'm creating new filter and check if it created successfully, I want to delete it and check if it also was successful.

First I created code and after it successfully ended my test I checked website, but still my created filter was there. After that I put first three rows to see what variables will be printed out and I see that IF statement not working properly. What kind of problem could be here?

# check if created filter appear in all filter list 
element = driver.find_element_by_xpath("//span[contains(., 'Filter created by automated tests')]") 
assert element.text == filter_name 
element.click()

# check if filter is deleted
print("Element: ", element)
print("Filter: ", filter_name)

if element == filter_name:
    print("Filter not deleted, there is problem, check test case")
else:
    print("Filter deleted successfully")

Result what I get:

Element:  <selenium.webdriver.firefox.webelement.FirefoxWebElement (session="32acd5e6-3a2e-4dba-a4f5-83c19400851e", element="4434f045-6b6d-4bd9-95c5-51a3b584b26a")>
Filter:  Filter created by automated tests
Filter deleted successfully

jeudi 31 octobre 2019

How to include a string being equal to itself shifted as a coniditon in a function definition?

I'm defining a simple if xxxx return y - else return NaN function that I want the if condition to be true when the input string is equal to input offset by 8 records

I've tried calling the record and setting it equal to itself offset by 8 using == and .shift(8)

def Growth (X):
    if X['Product'] == X['Product'].shift(8):
        return (1+ X['Sales'].shift(4)) / (1+ X['Sales'].shift(8) - 1)
    else:
        return 'NaN'

I expect the output to be NaN for the first 8 records, and then to have numbers at record 9, but I receive the error instead.

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().