concatenation

Concatenate StringVector with Rcpp

旧时模样 提交于 2019-12-07 12:23:13
问题 I can not figure out how to concatenate 2 strings with Rcpp; and the documentation did not help me while I suspect there is an obvious answer. http://gallery.rcpp.org/articles/working-with-Rcpp-StringVector/ http://gallery.rcpp.org/articles/strings_with_rcpp/ StringVector concatenate(StringVector a, StringVector b) { StringVector c; c= ??; return c; } I would expect this output : a=c("a","b"); b=c("c","d"); concatenate(a,b) [1] "ac" "bd" 回答1: There are probably a few different ways to

Is it possible to concatenate a list of strings using only a single allocation?

空扰寡人 提交于 2019-12-07 10:42:23
问题 After doing some profiling, we've discovered that the current way in which our app concatenates strings causes an enormous amount of memory churn and CPU time. We're building a List<string> of strings to concatenate that is on the order of 500 thousand elements long, referencing several hundred megabytes worth of strings. We're trying to optimize this one small part of our app since it seems to account for a disproportionate amount of CPU and memory usage. We do a lot of text processing :)

Save several ggplots to files

帅比萌擦擦* 提交于 2019-12-07 08:09:28
I want to save a changing set of ggplot is different files. To do this I use a for-loop looking something like this: save = c("plot1","plot2") for (i in 1:length(save)){ ggsave(cat(save[i],"\n"), file="i.pdf") } "plot1" and "plot2" are working ggplots (=names of the plot objects). Because I got the following error: Error in ggsave(cat(save[i], "\n"), file = "i.pdf") : plot should be a ggplot2 plot I tried the cat-function. It returns the same error with or without the function. If I enter the "plot" directly it works... What am I doing wrong? (Edited the example so there is more than one plot)

How to reduce generating files of SQL “Alter Table/Partition Concatenate” in Hive?

吃可爱长大的小学妹 提交于 2019-12-07 04:39:22
问题 Hive version: 1.2.1 Configuration: set hive.execution.engine=tez; set hive.merge.mapredfiles=true; set hive.merge.smallfiles.avgsize=256000000; set hive.merge.tezfiles=true; HQL: ALTER TABLE `table_name` PARTITION (partion_name1 = 'val1', partion_name2='val2', partion_name3='val3', partion_name4='val4') CONCATENATE; I use the HQL to merge files of specific table / partition. However, after execution there are still many files in output directory; and their size are far less than 256000000. So

Concatenate matrices/vectors in Python like in MATLAB?

扶醉桌前 提交于 2019-12-07 04:17:41
问题 Let A , x , y and z be some vectors or matrices of appropriate size. Then in MATLAB one can build a "super matrix" B out of them very easily: A = [1 2;3 4]; x = [4;5]; y = [1 2]; z = 4; B = [A x;y z]; The output is: >> B B = 1 2 4 3 4 5 1 2 4 What is the best way to achieve the same effect in NumPy? 回答1: You can use numpy.block: In [27]: a Out[27]: array([[1, 2], [3, 4]]) In [28]: x Out[28]: array([[4], [5]]) In [29]: y Out[29]: array([1, 2]) In [30]: z Out[30]: 4 In [31]: np.block([[a, x],

Combine two constant strings (or arrays) into one constant string (or array) at compile time

可紊 提交于 2019-12-07 03:32:44
问题 In C# and Java, it's possible to create constant strings using one or more other constant strings. I'm trying to achieve the same result in C++ (actually, in C++0x, to be specific), but have no idea what syntax I would use to achieve it, if such a thing is possible in C++. Here's an example illustrating what I want to do: #include <stdio.h> const char array1[] = "Hello "; const char array2[] = "world!\n"; const char array3[] = array1 + array2; // C++ doesn't like it when I try this int main()

how to concatenate two array element values in php by special charcter?

China☆狼群 提交于 2019-12-07 00:13:25
i have two arrays given below Array ( [0] => 2013-07-09 [1] => 2013-07-16 [2] => 2013-07-23 [3] => 2013-07-30 ) Array ( [0] => 2013-07-16 [1] => 2013-07-23 [2] => 2013-07-30 [3] => 2013-08-06 ) i want to concatenate two array element values by special character.given output below: Array ( [0] => 2013-07-09 : 2013-07-16 [1] => 2013-07-16 : 2013-07-23 [2] => 2013-07-23 : 2013-08-30 [3] => 2013-08-30 : 2013-08-06 ) Try with array_map like this $combined = array_map(function($a, $b) { return $a . ' : ' . $b; }, $array1, $array2)); Brissan $a1 = new ArrayIterator($array1); $a2 = new ArrayIterator(

Order before CONCAT_WS

风流意气都作罢 提交于 2019-12-06 21:31:28
I have a table with 3 Phone columns, I need to run some magic trying to get some records where the phone numbers could match between them, the problem is a Phone number could be on different field between the 2 records. So I think that a canonical string with the 3 phone numbers should allow me to make the comparison, the problem is the canonizing process. Is there a way to do this? I'm adding a snippet to illustrate what I need to do. Table is: ╔═════╦══════════╦══════════╦══════════╗ ║ ID ║ Phone1 ║ Phone2 ║ Phone3 ║ ╠═════╬══════════╬══════════╬══════════╣ ║ 123 ║ 555-1234 ║ 666-1235 ║ ║ ║

Is there an easy way to concatenate several lines of text into a string without constantly appending a newline?

扶醉桌前 提交于 2019-12-06 18:29:58
问题 So I essentially need to do this: String text = "line1\n"; text += "line2\n"; text += "line3\n"; useString( text ); There is more involved, but that's the basic idea. Is there anything out there that might let me do something more along the lines of this though? DesiredStringThinger text = new DesiredStringThinger(); text.append( "line1" ); text.append( "line2" ); text.append( "line3" ); useString( text.toString() ); Obviously, it does not need to work exactly like that, but I think I get the

When should you explicitly use a StringBuilder? [duplicate]

本小妞迷上赌 提交于 2019-12-06 16:52:33
问题 This question already has answers here : StringBuilder vs String concatenation in toString() in Java (18 answers) String concatenation in Java - when to use +, StringBuilder and concat [duplicate] (9 answers) Closed 5 years ago . As I understand it, when I do String baz = "foo" + "bar" + "123" the Java compiler internally replaces the expression with a StringBuilder . However our Java teacher told us that it is good practice to always use a StringBuilder explicitly... Am I correct in assuming