r - non-numeric argument to binary operator -


I have the data frame T that is a mixture of numeric and string:

  T1 & Lt; -C (1,2,3,4,6) T2 and LT; -C (4,5, 5,7,8) T3 and LT; -C ("A", "B", "C", "D", "E") T4 and LT; -C (4,5, 5,7,8) T5 and LT; -C (4,5, 5,7,8) T & LT; -Data Frame (T1, T2, T3, T4, T5)  

When I work on the numerical value of each row using the follwong code:

Apply

  P = (T, 1, Fun = function (x)) FLAC (x [1]> = x [4] + 2 * x [5], 1,0) ) It always gives an error message "Error 2 * x [5]: Non-numerical argument for binary operator" But if I replace T3 with all the numerical values, So it works perfectly.  

I'm surprised and wondering if anyone has any insight?

Thank you!

You get the force of each line because whatever T3 gets from your dataframe Has it been applicable . You can fix this with:

  P = apply (T [3], 1, FUN = function (x) ifelse (x [1]> = x [3] ] + 2 * X [4], 1,0))  

The error is not in comparison with the comparison but by attempting to multiply the character value by a numerical. This can also be successful with:

  P = apply (t, 1, mangle = function (x) ifelse (as.numeric (x [1]) gt; = as.numeric (X [4]) + 2 * as.numeric (x [5]), 1,0))  

But this is "just wrong". The appropriate apply is used for the matrix, where all the types of columns are the same, but it is usually slower than the vector-like functions such as ifelse Provide line-based processing without support should be for applicable :

  p = (t, iflesa (t1> = t 4 + 2 * t 5, 1,0))  

or simply use Boolean arithmetic and back numeric 0/1:

  with P = (T, as.numeric (T1> = T4 + 2 * T5)) # @ Kiron gets check  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -