character

R: Split character column and create two new ones

拈花ヽ惹草 提交于 2019-12-20 04:55:41
问题 R users I have a data frame similar to this: a <- c("John, 3 years") b <- c("Mokobe, 11 years") c <- c("Ivan") df <- rbind(a,b,c) df [,1] a "John, 3 years" b "Mokobe, 11 years" c "Ivan" Which function should I use to split the column after comma to get: df [,1] [,2] John 3 years Mokobe 11 years Ivan NA 回答1: we can do a strsplit by the delimiter , and then rbind the list elements after padding with NA at the end to make length same for each list element lst <- strsplit(df[,1], ", ") do.call

PHP MCRYPT encrypt/decrypt returns invisible strange characters?

老子叫甜甜 提交于 2019-12-20 04:13:57
问题 mcrypt_decrypt is giving me additional invisible characters which are NOT VISIBLE by just echoing out on the page. Can ONLY BE SEEN by writing it to the text file. Means, just displaying on the page is OK and hard to be noticed. Here is the code sample by Googling. Please guide me what is the correct usage is there's something wrong : function encrypt ($pure_string, $key) { $iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);

How to remove characters from a string, except those in a list

僤鯓⒐⒋嵵緔 提交于 2019-12-20 03:52:20
问题 This is my string value: string str = "32 ab d32"; And this list is my allowed characters: var allowedCharacters = new List<string> { "a", "b", "c", "2", " " }; I want it to become: str == " 2 ab 2"; I would like to replace any character that is not in the allowed character list, with an empty space. 回答1: Regex? Regex may be overkill for what you're trying to accomplish. Here's another variation without regex (modified your lstAllowedCharacters to actually be an enumerable of characters and

C program: how to find the maximum/minimum frequency of a character in a string

痞子三分冷 提交于 2019-12-20 03:50:34
问题 I am trying to find a way to get the values of max/min freq of characters in a string E.g. helpme would have max freq = 2 and min freq = 1 (there are 2 e's and there are other letters that occurs once) another E.g. aaaa would have max freq = 4 and min freq = 4 I am trying to program this, but I don't know what to do after I receive the string by using scanf. Assume that there are only lowercase and there are no space between words. Additionally, I prefer more of a brute force search over an

Split a column of character vectors and return a list

折月煮酒 提交于 2019-12-20 03:23:35
问题 I have the following dataframe : df <- data.frame(Sl.No = c(1:6), Variable = c('a', 'a,b', 'a,b,c', 'b', 'c', 'b,c')) Sl.No Variable 1 a 2 a,b 3 a,b,c 4 b 5 c 6 b,c I want to separate the unique values in the variable column as list myList <- ("a", "b", "c") I have tried the following code: separator <- function(x) strsplit(x, ",")[[1]][[1]] unique(sapply(df$Variable, separator)) This however gives me the following output: "a" I request some help. I have searched but seem unable to find an

Function Modifying a Character String

岁酱吖の 提交于 2019-12-20 03:10:35
问题 I need a function that will take input as a character string (BLANK) and print out the following: "Hello BLANK World" i.e., world("seven") prints out "Hello seven World" I'm very confused on how to work with character strings in R. 回答1: You want the function paste world <- function(x) paste("Hello", x, "World") 回答2: Or... x <- "seven" sprintf("Hello %s World", x) In other words no need for a world function as that's what sprintf does. 回答3: There's a tutorial on working with character strings

PHP only store 1048576 characters in array

北慕城南 提交于 2019-12-20 02:49:13
问题 I'm working on a project that parses huge text files and store some of the information in MySQL DB. I noticed one of the field was missing info when it was displayed, however, when checking the DB (from phpmyadmin), it shows the data is complete, so the problem must be with the php, before the length of the array field is 1048576, whereas there are 1235597 characters in DB. My php info shows memory_limit is 2048M, Mysql config shows: [mysqld] key_buffer = 32M max_allowed_packet = 32M I don't

Printing UTF-8-encoded byte string

情到浓时终转凉″ 提交于 2019-12-20 01:35:28
问题 I have a data of a form: v = "\xc5\x84" This is a byte representation of an utf-8 encoded character "ń". How can I print >>ń<< using variable v? I'm using python 2.7.2 In original the variable v contained string: v = "\\xc5\\x84" (double backslashes) vs v = "\xc5\x84" (single backslashes) which is by itself valid utf-8 character. 回答1: Edit In my machine the output depends on the shell/python used, as shown below. As commented by Klaus a major actor here would be the locale setting in your

Counting characters in a specific text file

佐手、 提交于 2019-12-19 21:53:14
问题 I need to count the vocals, consonants and all other characters in a specific text file. I created a script that counts the vocals and consonants, but I can't figure out how to count the rest of the characters. The goal is to count ALL characters, even if they're from another language, like Icelandic characters and signs like comma, full stop and exclamation mark. Here's my current code: Clear-Host $vocal = (Get-Content C:\Users\Administrator\Desktop\POWERSHELL\testfil.txt | Select-String

Error when converting dataframe row to character vector

ぐ巨炮叔叔 提交于 2019-12-19 21:27:44
问题 So I've got the following dataframe, datafr. X1 X2 X1.1 X2.1 Composite Element Composite Element 14-3-3_epsilon-M-C -0.8660101895 14-3-3_epsilon-M-C -0.6814387425 4E-BP1_pS65-R-V 0.1056560215 4E-BP1_pS65-R-V 0.1787506005 4E-BP1_pT37T46-R-V 0.6408257495 4E-BP1_pT37T46-R-V -0.7485933875 4E-BP1_pT70-R-C 0.6413568085 4E-BP1_pT70-R-C 0.9554481415 I want to make the second row the column names, so I look at the row datafr[1,] and everything is as it should be X1 X2 X1.1 X2.1 Composite Element