handling matrix in R -


I have such data

  SB1 SB2 SB 3 db 1 db2 db 3 dB 4 dB 5 fb fb 2 fb 3 fb 4 sb 1 ... -45 32 -4 10 -13-9 12 -45 -4 -43-2 -2 sb 2 45 ... 30 70 55 60 16 20 22 48 0 8 SB 3 -32 -30 ... -26 - 40 -10 -14 31 -10 -82-97 -4 dB 1 4 -706 ... -5 2 7 32 -4 0 -45 0 DB 2 -10-55 40 5 ... 2 3 26 -43 0 - 43 0 DB3 13 -60 10 -2 -2 ... -3 29 20 -4 -6 0 DB 49-61 14-7 - 3 3 ... 20 19 -30 -8 0 DB 5 -12 -20 -31 -32 -26 -29 -20 ... 0 -20 -23 -20 FB 1 45 -22 10 4 43-20-19 0 ... -20 -20 -20FB 2 4-48 82 0 0 4 30 20 20 ... 0 FB 3 43 0 97 45 43 6 8 23 20 0 ... 0 FB 4 2-84 020 20 0 0 ...  

What do I need The negative number is removed from the matrix and can be done with this command:

  Apply (difference, 2, function (x) {ifelse (x <0,0 , X)})  

However, this code removes both negative "N ..." which I want for further calculation. How can I remove negative but still preserve "..."? I have tried this code

  applied (inter base -2.2, function (x) {ifelse (x> 0% x% in% "...", x, 0 }})  

but it does not work and R gave me this warning

  error in applying (inter 1, 2, function (x Please give a positive length  

Please give me some advice and if you can, please tell me which best option to hand over data in the matrix form

Dhan Thanks.

Some things:

  1. Is this Class data. Frame is a purpose? Because then each column will be only one atomic type, which means that each element of your matrix is ​​of type character due to "...".

  2. If you really want to math, why do dots? You can not use them in a mathematical function in a meaningful way. Your function Not only works because the ">" operator compares the value of the alphabet if the letter Remove because their alphabet value is highe r in minus R.

  3. In the end, the argument with the applied () function MARGIN = 2 uses the full column as the input for the applied column, while every one what you want to do There are so many R functions vectors to apply a function for the element, but the work you want should be written with this in mind.

If you really want dots to stay the way, then you have to do a check for the first. One way to do this is:

  checkform & lt; - Function (x) {if (x == "...") Returns ("...") and {x & lt; - as.integer (x) x & lt; - ifelse (x> 0,0, x) returns (x)} data.frame (lapply (x = inter, fUN = function (x) {sapply (x = x, explanation: checkerfun) First element compare to dots If the element is something then it adds it to the integer and applies your replacement. Checkerphone is a function that expects the same element as input, not a vector such that it is of a type In the form of input in the methodology *. In the previous row, I have a spell in the nest Lapli occurs in: The difference runs the work on each difference, which is a list of atomic vectors. Therefore, the labor symbol of lapply () requires another sapply () function, on each element of each given vector The checker runs. 


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -