colvar in scatter3D return error " clim[2] - clim[1] : non-numeric argument to binary operator" - scatter3d

Hallo again dear forum,
I am not the best of friends with these 3D plots, and I struggle with simple formatting stuff. Like now, where I can't color my plots from a variable.
with(samples3d, {
s3d <- scatter3D(MDS2, MDS3, MDS1, pch = ifelse(meta$op.closed=="cl",22,21), type = "h",colvar = pcolor, lty.hplot=2, scale.y=0.75)
} )
It gives me this error:
Error in clim[2] - clim[1] : non-numeric argument to binary operator
I can read from the documentation that:
"colvar :The variable used for coloring. ... if
specified, it should be a vector of equal length as (x, y, z)."
So in my naïve approach I checked
colvec <- as.vector(samples3d$pcolor)
MDS1vec <- as.vector(samples3d$MDS1)
length(MDS1vec)
43
length(colvec)
43
- and they are the same length, so what is wrong here?
Best,
Mathilde

I also find the colouring scheme a bit difficult. But colvar should be a numeric vector, 1,2,3,4 up to number of groups you have. And then you have to supply col as another vector - having the length of the amount of groups. Scatter3D will then look up each of your numbers in that other vector, supplied as the argument 'col'. E.g.:
colvar <- as.numeric(as.factor(pcolor))
Now all your colours are made into numbers. And then:
col <-levels(as.factor(pcolor))
That's the col argument where the function can get the colours.

Without knowing what kind of data is in your vectors, I would assume from the error message that your pcolor vector is non-numeric.
A detailed answer to this error message is given here:
Non-numeric Argument to Binary Operator Error in R
A solution could be to code your groups in pcolor with numeric values. At least that worked for me, when I had this problem.

Related

What is the meaning of concatenation in the case of the cm operator in PDF?

I understand that "cm" concatenates two CTMs, however, it's not obvious to me what the specific definition of concatenation is. Reading through to "graphics state operators", in the specification, has not helped me.
Thus far I've looked at a whole bunch of different resources about matrix concatenation. There seems to be a number of different ways concatenation is defined for matrices: some examples seem to show it as:
[1,2; concat [5,6; = [1,2,5,6;
3,4] 7,8]. 3,4,7,8]
... however that would seem to break the transform matrices, so I assume that's not it.
Another option is that they just mean matrix addition:
[1,2; + [5,6; = [6 ,8 ;
3,4] 7,8]. 10,12]
but I feel, if it were just a matrix addition, they would just call it addition/matrix addition.
my last idea is:
[1,2; + [5,6; = [15,26 ;
3,4] 7,8]. 37,48]
but that seems like a bizarre approach, not least because it would have numbers behaving like text.
Thanks in advance

TfidfTransformer.fit_transform( dataframe ) fails

I am trying to build a TF/IDF transformer (maps sets of words into count vectors) based on a Pandas series, in the following code:
tf_idf_transformer = TfidfTransformer()
return tf_idf_transformer.fit_transform( excerpts )
This fails with the following message:
ValueError: could not convert string to float: "I'm trying to work out, in general terms..."
Now, "excerpts" is a Pandas Series consisting of a bunch of text strings excerpted from StackOverflow posts, but when I look at the dtype of excerpts,
it says object. So, I reason that the problem might be that something is inferring the type of that Series to be float. So, I tried several ways to make the Series have dtype str:
I tried forcing the column types for the dataframe that includes "excerpts" to be str, but when I look at the dtype of the resulting Series, it's still object
I tried casting the entire dataframe that includes "excerpts" to dtypes str using Pandas.DataFrame.astype(), but the "excerpts" stubbornly have dtype object.
These may be red herrings; the real problem is with fit_transform. Can anyone suggest some way whereby I can see which entries in "excerpts" are causing problems or, alternatively, simply ignore them (leaving out their contribution to the TF/IDF).
I see the problem. I thought that tf_idf_transformer.fit_transform takes as the source argument an array-like of text strings. Instead, I now understand that it takes an (n,2)-array of text strings / token counts. The correct usage is more like:
count_vect = CountVectorizer()
excerpts_token_counts = count_vect.fit_transform( excerpts)
tf_idf_transformer = TfidfTransformer()
return tf_idf_transformer.fit_transform( excerpts_token_counts )
Sorry for my confusion (I should have looked at "Sample pipeline for text feature extraction and evaluation" in the TfidfTransformer documentation for sklearn).

Error: Kotlin: The floating-point literal does not conform to the expected type Float

I was making a simple maths calculator in kotlin, an error appeared on my screen when I tried to initialize the value of one of the variables used as 0.00 for float integer.
var x:Float= readLine()!!.toFloat()
var y:Float= readLine()!!.toFloat()
var sum:Float=0.00// the error message is showcased in this line
sum=x+y
println("Addition " + sum)
This is a key difference between Java and Kotlin. Kotlin does not do numeric type promotion like Java does. The comments to your question are showing you how to deal with this, by either matching up the two types Double and/or Float to begin with, or by explicitly converting one or the other so that the two types match up.
Your problems goes away if you make use of Kotlin's ability to infer variable types by taking the type specifications off of your variable definitions. The fact that Kotlin infers types is one reason it does not promote numeric types. Mixing the two would lead to a lot of confusion.
Here's an example of how to fix and simplify your code's type mismatch issues using type inference:
var x = readLine()!!.toFloat()
var y = readLine()!!.toFloat()
var sum = x + y
println("Addition " + sum)
I understand that this may be just test code that you're using to understand Kotlin better. With that said, I'll point out that this code will crash if your user types in non-numeric input. You could fix this by putting a try/catch around your input lines, and providing an nice error message. You might want to put each input in a loop, continuing to ask for an input until the user does provide a response that is of the expected format.

Dataframes NAtype to binary Julia

I'm trying to write binary text files from a data frame in Julia using something along the lines of:
for x in RICT["$i"]["Sick"]
write(f9, convert(Int16, x ))
and everything works nicely except for when it comes to NA values. Missing values are treated as NA it seems, and I know that there are different ways of handling such values using the data frames package. Does anyone have any experience with these NAtypes? Should I convert the NAtypes to a more conventional type and then write them in? As always any help is much appreciated.
If you are writing a 16-byte integer value, there's no canonical representation of "blank", so you'd have to pick a special 16-byte integer value that represents NA. A common choice for this kind of thing is the smallest representable value – in this case typemin(Int16) == -32768. You can generalize this to other signed integer types.

What is the technical term for the input used to calculate a checkdigit?

For example:
code = '7777-5';
input = code.substring(0, 4); // Returns '7777'
checkdigit = f(input); // f() produces a checkdigit
assert.areEqual(code, input + "-" + checkdigit)
Is there a technical term for input used above?
Specifically I'm calculating checkdigits for ISBNs, but that shouldn't effect the answer.
Is "original number excluding the check digit" technical enough? :)
Actually, it's often the case, as in the link you posted, that the check digit or checksum ensures a property about the full input:
...[the check digit] must be such that the sum of all the ten digits, each multiplied by the integer weight, descending from 10 to 1, is a multiple of the number 11.
Thus, you'd check the full number and see if it meets this property.
It's "backwards" when you're initially generating the check digit. In that case, the function would be named generate_check_digit or similar, and I'd just name its parameter as "input".
Although I am not sure if there is a well-known specific technical term for the input, what LukeH suggested (message/data) seems common enough.
Wiki for checksum:
With this checksum, any transmission error that flips a single bit of the message, or an odd number of bits, will be detected as an incorrect checksum
Wiki for check digit:
A check digit is a form of redundancy check used for error detection, the decimal equivalent of a binary checksum. It consists of a single digit computed from the other digits in the message.