Search Results

Search found 1545 results on 62 pages for 'manipulation'.

Page 27/62 | < Previous Page | 23 24 25 26 27 28 29 30 31 32 33 34  | Next Page >

  • Finding the Column Index for a Specific Value

    - by Btibert3
    Hi All, I am having a brain cramp. Below is a toy dataset: df <- data.frame( id = 1:6, v1 = c("a", "a", "c", NA, "g", "h"), v2 = c("z", "y", "a", NA, "a", "g"), stringsAsFactors=F) I have a specific value that I want to find across a set of defined columns and I want to identify the position it is located in. The fields I am searching are characters and the trick is that the value I am looking for might not exist. In addition, null strings are also present in the dataset. Assuming I knew how to do this, the variable position indicates the values I would like returned. > df id v1 v2 position 1 1 a z 1 2 2 a y 1 3 3 c a 2 4 4 <NA> <NA> 99 5 5 g a 2 6 6 h g 99 The general rule is that I want to find the position of value "a", and if it is not located or if v1 is missing, then I want 99 returned. In this instance, I am searching across v1 and v2, but in reality, I have 10 different variables. It is also worth noting that the value I am searching for can only exist once across the 10 variables. What is the best way to generate this recode? Many thanks in advance.

    Read the article

  • Macros to set and clear bits

    - by volting
    Im trying to write a few simple macros to simplify the task of setting and clearing bits which should be a simple task however I cant seem to get them to work correctly. #define SET_BIT(p,n) ((p) |= (1 << (n))) #define CLR_BIT(p,n) ((p) &= (~(1) << (n)))

    Read the article

  • finding and returning a string with a specified prefix

    - by tipu
    I am close but I am not sure what to do with the restuling match object. If I do p = re.search('[/@.* /]', str) I'll get any words that start with @ and end up with a space. This is what I want. However this returns a Match object that I dont' know what to do with. What's the most computationally efficient way of finding and returning a string which is prefixed with a @? For example, "Hi there @guy" After doing the proper calculations, I would be returned guy

    Read the article

  • bitshift large strings for encoding QR Codes

    - by icekreaman
    As an example, suppose a QR Code data stream contains 55 data words (each one byte in length) and 15 error correction words (again one byte). The data stream begins with a 12 bit header and ends with four 0 bits. So, 12 + 4 bits of header/footer and 15 bytes of error correction, leaves me 53 bytes to hold 53 alphanumeric characters. The 53 bytes of data and 15 bytes of ec are supplied in a string of length 68 (str68). The problem seems simple enough - concatenate 2 bytes of (right-shifted) header data with str68 and then left shift the entire 70 bytes by 4 bits. This is the first time in many years of programming that I have ever needed to do something like this, I am a c and bit shifting noob, so please be gentle... I have done a little investigation and so far have not been able to figure out how to bitshift 70 bytes of data; any help would be greatly appreciated. Larger QR codes can hold 2000 bytes of data...

    Read the article

  • [Java] Cut <br/>-Tags from String end

    - by Robert M.
    Hello everybody, I am currently developing a Web-Application using Java EE where I'm using a Rich-Javascript-Editor (http://www.primefaces.org/showcase/ui/editor.jsf). As the user can easily add too many linebreaks that will be convertet to linebreak-tags, I need to remove all these Tags from the end of a String. Is there an elegant way of using Regex to accomplish this? An example String would be: "This is a test <b>bold</b><br/><br/>" Where obviously the last two tags have to be removed. Thank you in advance for any help Best Regards, Robert

    Read the article

  • How should images be stored when multiple sizes are needed?

    - by Josh Curren
    What is the best way to store images? Currently when an image is uploaded I resize it to 3 different sizes (a thumbnail, a normal size, and a large size). I save in a database a description of the image, the format, and use the id number from the database as the image name. Each size image has its own directory. Should I be storing the images in the database? Should I only be storing the larger size and generate the thumbnail as needed? Or any other ideas you have?

    Read the article

  • How to remove characters from a string?

    - by masato-san
    Hi, Below is interview question so you cannot relay on the functions that predefined in libraries. Also my answer below set the element to null but there is another ways to solve the problem. Given string $string = "This is a pen", remove "is" so that return value is "Th a pen" (including whitespece). I've tried (shown below) but returned value is not correct. Thanks in advance! function remove_delimiter_from_string(&$string, $del) { for($i=0; $i<strlen($string); $i++) { for($j=0; $j<strlen($del); $j++) { if($string[$i] == $del[$j]) { $string[$i] = $string[$i+$j]; //this grabs delimiter :( } } } echo $string . "\n"; }

    Read the article

  • Replace string with incremented value

    - by Andrei
    Hello, I'm trying to write a CSS parser to automatically dispatch URLs in background images to different subdomains in order to parallelize downloads. Basically, I want to replace things like url(/assets/some-background-image.png) with url(http://assets[increment].domain.com/assets/some-background-image.png) I'm using this inside a class that I eventually want to evolve into doing various CSS parsing tasks. Here are the relevant parts of the class : private function parallelizeDownloads(){ static $counter = 1; $newURL = "url(http://assets".$counter.".domain.com"; The counter needs to be reset when it reaches 4 in order to limit to 4 subdomains. if ($counter == 4) { $counter = 1; } $counter ++; return $newURL; } public function replaceURLs() { This is mostly nonsense, but I know the code I'm looking for looks somewhat like this. Note : $this-css contains the CSS string. preg_match("/url/i",$this->css,$match); foreach($match as $URL) { $newURL = self::parallelizeDownloads(); $this->css = str_replace($match, $newURL,$this->css); } }

    Read the article

  • Removing a pattern from the beggining and end of a string in ruby

    - by seaneshbaugh
    So I found myself needing to remove <br /> tags from the beginning and end of strings in a project I'm working on. I made a quick little method that does what I need it to do but I'm not convinced it's the best way to go about doing this sort of thing. I suspect there's probably a handy regular expression I can use to do it in only a couple of lines. Here's what I got: def remove_breaks(text) if text != nil and text != "" text.strip! index = text.rindex("<br />") while index != nil and index == text.length - 6 text = text[0, text.length - 6] text.strip! index = text.rindex("<br />") end text.strip! index = text.index("<br />") while index != nil and index == 0 text = test[6, text.length] text.strip! index = text.index("<br />") end end return text end Now the "<br />" could really be anything, and it'd probably be more useful to make a general use function that takes as an argument the string that needs to be stripped from the beginning and end. I'm open to any suggestions on how to make this cleaner because this just seems like it can be improved.

    Read the article

  • How to find image width and height dynamically and specify height, width attibutes if over certain d

    - by Wbdvlpr
    Hi, I display some data on my website and one of the data feed elements is an image. [title] => Product title [description] => some description [image] => www.some-domain.com/product-image/p12345.jpg I then display this image using <img alt="product" src="<?=$data['image']?>" /> Most of the images are 80x80, 120x100 or other less than 150 in width, which perfectly fit in the website template, but some of them are quite large such as 800x600 which distort the layout. I want a control on these types. I tried to set WIDTH="150", but as the width vary they dont look good. I was thinking If I could set a fixed width to images, say, larger than 250px then I can live with it for now. Any ideas how to achieve this? Thanks

    Read the article

  • Efficient way in Python to remove an element from a comma-separated string

    - by ensnare
    I'm looking for the most efficient way to add an element to a comma-separated string while maintaining alphabetical order for the words: For example: string = 'Apples, Bananas, Grapes, Oranges' subtraction = 'Bananas' result = 'Apples, Grapes, Oranges' Also, a way to do this but while maintaining IDs: string = '1:Apples, 4:Bananas, 6:Grapes, 23:Oranges' subtraction = '4:Bananas' result = '1:Apples, 6:Grapes, 23:Oranges' Sample code is greatly appreciated. Thank you so much.

    Read the article

  • Distributing a function over a single dimension of an array in MATLAB?

    - by Alex Feinman
    I often find myself wanting to collapse an n-dimensional matrix across one dimension, and can't figure out if there is a concise incantation I can use to do this. For example, when parsing an image, I often want to do something like this. (Note! Illustrative example only. I know about rgb2gray for this specific case.) img = imread('whatever.jpg'); s = size(img); for i=1:s(1) for j=1:s(2) bw_img = mean(img(i,j,:)); end end I would love to express this as something like: bw = on(color, 3, @mean); or bw(:,:,1) = mean(color); Is there a short way to do this?

    Read the article

  • How to turn such string into a data grid? (C# .Net)

    - by Ole Jak
    So I have such string (recived from php server... normal print_r of array) Array ( [item_number_in_array] => Array ( [id] => id_value [title] title_value_as_string_vith_spaces [content] => content_value_as_string_vith_spaces ) [item_number_in_array]... ) I need any how to represent it as table like this in C# How to do such thing?

    Read the article

  • How to lowercase every element of a collection efficiently?

    - by Chris
    Whats the most efficient way to lower case every element of a list or set? My idea for a List: final List<String> strings = new ArrayList<String>(); strings.add("HELLO"); strings.add("WORLD"); for(int i=0,l=strings.size();i<l;++i) { strings.add(strings.remove(0).toLowerCase()); } is there a better, faster way? How would this exmaple look like for a set? As there is currently no method for applying an operation to each element of a set (or list) can it be done without creating an additional temporary set? Something like this would be nice: Set<String> strings = new HashSet<String>(); strings.apply( function (element) { this.replace(element, element.toLowerCase();) } ); Thanks,

    Read the article

  • Find a part of UNC path and put in a variable?

    - by Refracted Paladin
    I am trying to peel off the last part of a unc path that is being passed and put it in a variable to use in a method further down the line. Example path would be -- \\ourfileserver\remoteuploads\countyfoldername\personfoldername How do I peel just the countyfoldername out of that? I had thought to try var th = e.FullPath.LastIndexOf('\\'); var whichFolder = folderPath.Substring(th); but that is an escape character and it doesn't like @ either. Is this even the right direction?

    Read the article

  • How to add dimensions to dynamic img elements (Updated)

    - by Mohammad
    I use a Json call to get a list of image addresses, then I add them individually to a div like this. Unfortunately the image dimension is not part of the Json information. <div id="container"> <img src="A.jpg" alt="" /> <img src="B.jpg" alt="" /> ... </div> Do any of you JQuery geniuses know of a code that would flawlessly and dynamically add the true Width and Height to each img element in the container as soon as each individual one is rendered? I was thinking maybe the code could do a image width check width > 0 to evaluate when the image has actually been rendered, then fire. But I wouldn't know how to go about that and make it work stably. How is the best way of going about this? Thank you so much! Update, As the answers point out, adding Width or Height to the elements is pretty routine. The problem here is actually writing a code that would know when to do that. And evaluate that condition for each image not the page as a whole.

    Read the article

< Previous Page | 23 24 25 26 27 28 29 30 31 32 33 34  | Next Page >