Using complex comparators in tsung script - tsung

Is it possible to use an if condition in tsung and use a greater than comparison rather than a straight equals and not equals comparison?
Or is it possible to use the and or or operator to combine comparisons?

There is no greather then operator at this time in tsung, only equal and not equal. It is not possible to combine comparisons with and and or.

Related

Using findall with multiple criteria

The following code finds the indexes in the 50th column of p where the value is equal to 1.
findall(p[:,50].== 1)
But suppose I was interested in screening for multiple criteria. For example, if I was also interested in the indexes where the value is 0.5. I have tried the following in that case, but something goes wrong:
findall(p[:,50].== 1 | p[:,50].== 0.5)
You're forgetting to dot the | operator. But you also need to use parens:
findall((p[:,50].== 1) .| (p[:,50].== 0.5))
But still, this is a bit wasteful, since you are making two copies of the same column, and are allocating five intermediate vectors that you don't need. You should try to use a predicate function to avoid this, like e.g. here:
findall(x->x in (0.5, 1.0), p[:,50])
or
findall(x->x==0.5||x==1, p[:,50])
On top of this, you can use view to avoid allocations due to p[:,50]:
findall(x->x==0.5||x==1, view(p, :,50))

Using compound inequalities within ifelse() in R

I am trying to create a new factor variable that is conditional based on a numeric variable within my dataframe. my ifelse argument works perfectly when I supply it a single inequality, but for the two categories that require a compound inequality, it doesn't work. I'm familiar with logic and conditions in other languages, and I'm thinking just my syntax is off?
Also, there seems to be times when you can use '&' and times to use '&&'. I'm used to always using '&&', so what is the difference here?
data$bin<-as.factor(ifelse(data$internet<=2.3225,"one",
ifelse(data$internet>2.3225 && data$internet<=4.425,"two",
ifelse(data$internet>4.425 && data$internet<=6.5275,"three",
ifelse(data$internet>6.5275,"four",NA)))))
&& doesn't vectorize. Unless you want to compare a single element to a single element, you should use &.

Cleaning data which to use (Grep) or (str_extract_all)

I need to extract from the dataset all the elements that mention "mean" and "std" which is standard deviation.
example of how it is written in feat, the column 2, the variables.
Goal> I am trying to extract only the elements that have this written.
"tBodyAcc-mean()-Z"
"tBodyAcc-std()-X"
feat<-read.table("features.txt")
I assumed that using
grep("mean"&"std",feat[,2])
would work
But does not work, I have this error:
"operations are possible only for numeric, logical or complex types"
I found someone who has used this:
meansd<-grep("-(mean|std)\\(\\)",feat[,2])
It worked fine but I do not understand the meaning of the backlashes.
I don't understand what it exactly means and I don't want to use it.
What you need is an alternation operator | in a regex pattern. grep allows using literal values (when fixed=TRUE is used) or a regular expression (by default).
Now, you found:
meansd<-grep("-(mean|std)\\(\\)",feat[,2])
The -(mean|std)\(\) regex matches a -, then either mean or std (since (...) is a grouping construct that allows enumerating alternatives inside a bigger expression), then ( and then ) (these must be escaped with a \ literal symbol - that is why it is doubled in the R code).
If you think the expression is an overkill, and you only want to find entries with either std or mean as substrings, you can use a simpler
meansd<-grep("mean|std",feat[,2])
Here, no grouping construct is necessary since you only have two alternatives in the expression.

regarding matrix comparison in R

Currently, I have two matrixes, and want to compare it and see whether they are exactly equivalent. In R, is there any function to do that?
As stated above start with ?all.equal or ?identical. If you then find that your matrices are unequal, you may want to compare them column by column. This might do the trick:
mapply(as.data.frame(m1),as.data.frame(m2),FUN=function(v1,v2) all(v1==v2) )

VB script math function

I have an ASP page where I have 2 variables, strActualRate and strProposed.
The values are:
strActualRate = 33.30
strProposed = 33.3
So when I write the following line to compare:
if strActualRate <> strProposed then
Response.Writr "Both are not equal!"
end if
I am getting the output "Both are not equal", even though both are the same.
I am sure that I need to use some mathematical conversion function to compare.
Can anyone tell me how to solve this ?
Thanks in advance!
If I understand correctly, you think the two values are equal but because VBScript is comparing strings rather than numbers the two are coming back as not equal.
You're correct in the conversion idea, and here's the code:
if CDbl(strActualRate) <> CDbl(strProposed) then
Response.Write "Both are not equal!"
end if
That will convert your string values to numbers to do the comparison.
Your question doesn't really add up, so I'm not really sure what the problem is. I will try to clear up some things about data types and comparison.
You are using the prefix "str" for your variables which suggests that you intend to store string values in them, however you are instead storing numeric values in them. Either you are confused about how hungarian notation is used to keep track of the data type, or the code that you posted does not look like the code that you are actually using.
The numeric value 33.30 is exactly the same as the value 33.3. If you instead would have used the string values "33.30" and "33.3", they would be two strings that are not equal.
If your code is corrected (Response.Write instead of Response.Writr) so that it runs, it will not produce any output at all. As the values are equal, the condifion in the if statement evaluates to false.
If you do in fact assign string values to the variables, the code would output "Both are not equal!". This is just as expected as the strings are not equal. If you have strings and want to compare them as numerical values, you have to comvert them:
If CDbl(strActualRate) <> CDbl(strProposed) Then
Response.Write "Both are not equal!"
End If
Try casting the values to a double in the comparison statement with CDbl()
Are you intending to perform the comparison as strings, floating point numbers or some other method? If you are comparing them as strings, then clearly they are not equal, as one of them has an extra zero on the end. If you are comparing them as floating point numbers, then you generally want to use a comparison that involves taking the difference and checking that it is smaller than some small value. This is because floating point number calculations involve some degree of inaccuracy and comparisons between them can fail because of the underlying representation.

Resources