R function for counting how often a value falls below a particular value -


With zero experience in the RP script it is proving to be a monster for me I have a data frame with 57 columns , 30 rows of data

What I'm trying to do here:

1) Go to each column:

2) Number of times 2 / Continuous values ​​are less than 1 / 3/4/5/6/7/8/9.

3) Print the result as a text file

4) Repeat steps 2 and 3 for the second column, and

I surround

This is a column my data: data & lt; -c (-0.996, -1.111, -0.638,0.047,0.694,1.901,2.863,2.611,2,56,2.016,0.929, -0.153, -0.617, - 0.143 0.199,0.556,0.353, -0.638,0.347,0.045 , -0.829, -0.882, -1.143, -0.869,0.619,0.923, -0.474,0.227 0.394,0.789,1.962,1.132,0.1, -0.278, -0.303, -0.606, -0.705, -0.858, -0.723, - 0.081,1.206,2.329 1.863,2.1,1,547,2.026,0.015, -0.441, -0.371, -0.304, -0.668, -0.953, -1.256, -1.185, - 0.891, -0.569 0.485,0.421, -0.004.0.024, -0.39, -0.58, -1.178, -1.101, -0.882,0.01,0.052, -0.166, -1.703, -1.048 -0.718, -0.036, -0.561, -0.08,0.272, -0.041, -0.811, -0.929 , -0.853, -1.047,0.431,0.576,0.642,1.62 2.324,1.251,1.384,0.195, -0.081, -0.335, -0.176,1.089, -0.602, -1.134, -1.356, -1.203, -0.795, -0.752 -0.692, -0.813, -1.172, -0.387, -0.079, -0.374, -0.157, 0.263,0.313,0.975,2.298,1.71,0.229, -0.313 -0.779, -1.12, -1.102, -1.01, -0.86, -1.118, -1.211, -1.081, -1.156, -0.972)

When I run the following code:

  (Col: ncol (data) 1) {Run & lt; - rle (data [, color]) print ($ runs length [which runs ($ value <1)]}   

this gives me:

[1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

The number of values ​​has been calculated & lt; -1 but do not run, is there anything that I am here during the wrong?

(mass editing)

Fixed data vector (comma missing):

  Data & lt; - c (-0.996, -1.111, -0.638,0.047,0.694,1.901,2.863,2.611,2,56,2.016,0.99 2, -0.153, -0.617, -0.143, 0.199,0,556,0.353, -0.638, 0.347,0.045, -0.829, -0.882, -1.143, -0.869,0.619,0.923, -0.474,0.227, 0.394,0.789,1.962,1.132, 0.1, -0.278, -0.303, -0.606, -0.705, -0.858, -0.723, -0.081,1.206,2.329, 1.863,2.1,1,547,2.026,0.015, -0.441, -0.371, -0.304, -0.668, -0.953, -1.256, -1.185, -0.891, -0.569, 0.485,0421 , -0.004,0.024, -0.39, -0.58, -1.178, -1.101, -0.882,0.01,0.052, -0.166, -1.703, - 1.048, -0.718, -0.036, -0.561, -0.08,0.272, -0.041 , -0.811, -0.929, -0.853, -1.047,0.431,0.576,0.642,1.62, 2.324,1.251,1.384,0.195, -0.081, -0.335, -0.176,1.089, -0.602, -1.134, -1.356, - 1.203, -0.795, -0.752, -0.692, -0.813, -1.172, -0.387, -0.079, -0.374, -0.157,0.263,0.313, 0.975,2.298,1.71,0.229, -0.313, -0.779, -1.12, -1.102, -1.01, -0.86, -1.118, -1.211, -1.081, -1.156, -0.972)   

do data & lt; -1 gives you a logical vector, and we get the TRUE & amp; FALSE :

  Runs & lt; - rle (data & lt; -1) print (run) ## run length encoding ## length: int [1:21] 1 1 20 1 2 9 2 8 2 4 2 ... ## Value: logos [1 : 21] Lies true lies true lies ...   

Then only remove the length TRUE Run:

  print ( Run $ length [which runs ($ values)] ## [1] 1 1 2 2 2 1 3 1 3 4   

And repeat the data already shown with the column of frames: # Create a data frame from sampled versions of data sets .seed (1492) # Repeatable df & lt; - data.frame (v1 = data, v2 = sample (data, length) (Data), est = TRUE), V3 = sample (data, length, data), replacement = TRUE, V4 = sample, length (data), replacement = TRUE) for extraction (1 in curl: ncol (df)) {run & Lt; - rle (df [, col] <-1 lt; print (run $ length [that ($ value runs)]) ## [1] 1 1 2 2 2 1 3 1 3 4 ## [ 1] 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 ## [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 ## [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -