repeat

Sequence reduction in R

最后都变了- 提交于 2019-12-07 07:30:53
问题 Assume you have a vector like so: v <- c(1,1,1,2,2,2,2,1,1,3,3,3,3) How can it be best reduced to a data.frame like this? v.df <- data.frame(value=c(1,2,1,3),repetitions=c(3,4,2,4)) In a procedural language I might just iterate through a loop and build the data.frame as I go, but with a large dataset in R such an approach is inefficient. Any advice? 回答1: or more simply data.frame(rle(v)[]) 回答2: with(rle(v), data.frame(values, lengths)) should get you what you need. values lengths 1 3 2 4 1 2

Three.js Repeat texture fail

允我心安 提交于 2019-12-06 14:11:42
I'm trying to make a simple floor texture, but it seems that wrapS and wrapT don't works. Look at the result: http://hpics.li/321350c var texture = THREE.ImageUtils.loadTexture( "Game/Texture/drytext.png" ); texture.wrapS = THREE.RepeatWrapping; texture.wrapT = THREE.RepeatWrapping; texture.repeat.set( 4, 4 ); var floorMaterial = new THREE.MeshBasicMaterial( { map: texture, side: THREE.DoubleSide }); var floorGeometry = new THREE.PlaneGeometry(20, 20, 10, 10); var floor = new THREE.Mesh(floorGeometry, floorMaterial); floor.rotation.x = -Math.PI / 2; scene.add(floor); Thank you 来源: https:/

Javascript Repeating Audio

半世苍凉 提交于 2019-12-06 13:08:36
I have been trying to get this JavaScript to repeat the audio once it has finished, I have had a look around and I am inexperienced with JavaScript, although I have made attempts tweaking and researching I have had no luck so far. I would be very grateful for any help and tips Many thanks- Grant <!-- Script inside body --> <!-- Audio Player --> <script> $(document).ready(function() { var audioElement = document.createElement('audio'); audioElement.setAttribute('src', 'music/audio.mp3'); audioElement.setAttribute('play', 'autoplay'); //audioElement.load() $.get(); audioElement.addEventListener(

mySQL Repeating Events Query

ぐ巨炮叔叔 提交于 2019-12-06 10:36:17
问题 There are some solutions, but i don't know how to change that for my table. So i hope someone could help me. I have the following Table ╔═════╦═════════╦════════════╦════════════╦═══════════╗ ║ UID ║ TITLE ║ BEGIN ║ END ║ RECURRING ║ ╠═════╬═════════╬════════════╬════════════╬═══════════╣ ║ 1 ║ event A ║ 1359741600 ║ 1359745200 ║ none ║ ║ 1 ║ event B ║ 1359741600 ║ 0 ║ daily ║ ║ 1 ║ event C ║ 1359741600 ║ 0 ║ weekly ║ ║ 1 ║ event D ║ 1359741600 ║ 0 ║ monthly ║ ║ 1 ║ event E ║ 1359741600 ║ 0 ║

functional programming algorithm for finding repeated characters

*爱你&永不变心* 提交于 2019-12-06 06:17:42
I am converting the "zxcvbn" password strength algorithm from JavaScript to Scala. I am looking for a pure functional algorithm for finding sequences of repeating characters in a string. I know that I can translate the imperative version from JavaScript, but I would like to keep this as side-effect free as possible, for all the reasons usually given for functional programming. The algorithm can be in Scala, Clojure, Haskell, F#, or even pseudocode. Thanks. Using Haskell's standard higher-order functions: Data.List.group finds runs of equal elements in a list: > group "abccccdefffg" ["a","b",

Alternatives for AlarmManager setRepeating in API 19 and above?

岁酱吖の 提交于 2019-12-06 05:36:14
My app requires very accurate timing of a repeating alarm. Since API 19 the AlarmManager setRepeating is now inexact to save battery ( Save the trees and all ). Is there any workaround to get API 19's setExact method to work on a loop? Note: as of API 19, all repeating alarms are inexact. If your application needs precise delivery times then it must use one-time exact alarms, rescheduling each time as described above. Legacy applications whose targetSdkVersion is earlier than API 19 will continue to have all of their alarms, including repeating alarms, treated as exact. Is there any workaround

MATLAB: create a large matrix by repeating elements of a vector, with increasing stride for each column

大城市里の小女人 提交于 2019-12-06 05:25:28
In MATLAB I have a vector x of length n, where n is usually O(10), and I would like to build a tall matrix A of size [n^m,m], where m is again 0(10). The matrix has a peculiar form: if n=4 and m=6, let x=[x1; x2; x3; x4] then A is x1 x1 x1 x1 x1 x1 x2 x1 x1 x1 x1 x1 x3 x1 x1 x1 x1 x1 x4 x1 x1 x1 x1 x1 x1 x2 x1 x1 x1 x1 x2 x2 x1 x1 x1 x1 x3 x2 x1 x1 x1 x1 x4 x2 x1 x1 x1 x1 x1 x3 x2 x1 x1 x1 . . . . . . x4 x4 x4 x4 x4 x4 In practice, each column is obtained by repeating the elements of x, with an increasing stride for each column. How can I do that? If possible, I'd prefer an efficient

How to idiomatically call C++ functions based on variable value?

不问归期 提交于 2019-12-06 03:49:59
问题 Suppose I have a data type enum TreeTypes { TallTree, ShortTree, MediumTree } . And I have to initialize some data based on one particular tree type. Currently I have written this code: int initialize(enum TreeTypes tree_type) { if (tree_type == TallTree) { init_tall_tree(); } else if (tree_type == ShortTree) { init_short_tree(); } else if (tree_type == MediumTree) { init_medium_tree(); } return OK; } But this is some kind of stupid code repetition. I am not using any of the powerful C++

How to use the {n} syntax of regex with CMake

强颜欢笑 提交于 2019-12-05 20:53:05
I have this string "2017-03-05-02-10-10_78205" and I want to match it with this pattern [0-9]{4}(-[0-9]{2}){5}_[0-9]+ but it doesn't work on CMake. See this example in CMake : set(stuff "2017-03-05-02-10-10_78205") if( "${stuff}" MATCHES "[0-9]{4}(-[0-9]{2}){5}_[0-9]+") message("Hello") endif() CMake doesn't seem to support the syntax {n} . Obviously, I solved my problem with that pattern [0-9-]+_[0-9]+ Nevertheless, I would like to know if I'm doing something wrong with the syntax {n} . Is it supported by CMake ? If not, how to define a specific number of repetition with CMake ? I'm using an

Sequence reduction in R

ⅰ亾dé卋堺 提交于 2019-12-05 15:12:05
Assume you have a vector like so: v <- c(1,1,1,2,2,2,2,1,1,3,3,3,3) How can it be best reduced to a data.frame like this? v.df <- data.frame(value=c(1,2,1,3),repetitions=c(3,4,2,4)) In a procedural language I might just iterate through a loop and build the data.frame as I go, but with a large dataset in R such an approach is inefficient. Any advice? or more simply data.frame(rle(v)[]) with(rle(v), data.frame(values, lengths)) should get you what you need. values lengths 1 3 2 4 1 2 3 4 来源: https://stackoverflow.com/questions/3010790/sequence-reduction-in-r