names

R Error: names() applied to a non-vector

家住魔仙堡 提交于 2019-12-05 09:51:36
问题 I have a chunk of code which produces an error only the first time I run it. Strangely if I run it a second time I get no error (craziness definition?). Also the error does not show up always at the same position, I mean that if I add a few lines of comments the error message is printed after the comments and not after a specific instruction. I cannot provide a reproducible example because I do not know where exactly the error comes from. The error is the following: Error in names(frame)

Training solr to recognize nicknames or name variants

被刻印的时光 ゝ 提交于 2019-12-05 06:34:49
问题 I'm pretty sure that solr can be set up to recognize synonyms during searches. I'm wondering if it's possible to do the same with nicknames -- so for example searches for "Robert" would pull up records with "Bob" in them. 回答1: Just found a page where someone named Jon Moniaci exactly how to do this: http://bitsandpieces.jonmoniaci.com/2010/05/searching-common-nicknames-in-solr/ Basically, create a synonyms file with lines like so: Bob, Robert, Bobby (Jon's file is here, derived from the

You can abbreviate list names? Why?

做~自己de王妃 提交于 2019-12-04 22:58:50
This got me pretty bad. You can abbreviate list names? I never noticed it before and I got totally screwed for like a day. Can someone explain what is happening here and why it could be more useful than it is terrible? And why its inconsistent like that at the bottom? And if I can turn it off? > wtf <- list(whatisthe=1, pointofthis=2) > wtf$whatisthe [1] 1 > wtf$what [1] 1 > wtf <- list(whatisthe=1, whatisthepointofthis=2) > wtf$whatisthepointofthis [1] 2 > wtf$whatisthep [1] 2 > wtf$whatisthe [1] 1 > wtf$what NULL I suspect that partial matching by the $ operator was a nice(r) feature for

Creating file names automatically C++

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 09:40:00
问题 I'm trying to write a program in C++, which creates some files (.txt) and writes down the result in them. The problem is that an amount of these files is not fixed at the beginning and only appears near the end of the program. I would like to name these files as "file_1.txt", "file_2.txt", ..., "file_n.txt", where n is an integer. I can't use concatenation because the file name requires type "const char*", and I didn't find any way to convert "string" to this type. I haven't found any answer

Losing names of dimnames of a table after cbind or rbind

对着背影说爱祢 提交于 2019-12-04 09:28:44
After cbind or rbind -ing a table object (for example, adding a margin of sums or somesuch), names of dimnames get lost (see y ). I found this "workaround" but was wondering if there's an out of the bag solution to this that looks less hacky. Perhaps something that can be done on the fly? I would like to keep the object of class table . > (x <- table(1:3, sample(1:3), dnn = c("rows", "cols"))) cols rows 1 2 3 1 1 0 0 2 0 0 1 3 0 1 0 > (y <- cbind(x, "4" = 4:6)) # "rows" and "cols" get lost 1 2 3 4 1 1 0 0 4 2 0 0 1 5 3 0 1 0 6 > names(dimnames(y)) <- names(dimnames(x)) > y cols rows 1 2 3 4 1

use first row data as column names in r

无人久伴 提交于 2019-12-04 08:27:39
问题 This should be such an easy problem but I have trouble with. I have a dirty dataset that I could not read it with header=T . After I read and clean it, I would like to use the now first row data as the column name. I tried multiple methods on stackoverflow without success. What could be the problem? The dataset t1 should look like this after clean up: V1 V2 V3 V4 V5 1 col1 col2 col3 col4 2 row1 2 4 5 56 3 row2 74 74 3 534 4 row3 865 768 8 7 5 row4 68 86 65 87 I tried: colnames(t1)=t1[1,] .

Preserve names when coercing vector from binary to `as.numeric`?

微笑、不失礼 提交于 2019-12-03 23:02:15
In R, when you coerce a vector from binary to numeric, the names are stripped away. There are a few possible solutions, which I've outlined before. It seems dangerous to rely on implicit conversion by adding 0 to all the values, and the sapply() adds an additional loop to my operations (which seems inefficient). Is there any other way to preserve the names when converting a vector using as.numeric ? # Set the seed set.seed(1045) # Create a small sample vector and give it names example_vec <- sample(x = c(TRUE,FALSE),size = 10,replace = TRUE) names(example_vec) <- sample(x = LETTERS,size = 10

R Error: names() applied to a non-vector

这一生的挚爱 提交于 2019-12-03 22:29:25
I have a chunk of code which produces an error only the first time I run it. Strangely if I run it a second time I get no error (craziness definition?). Also the error does not show up always at the same position, I mean that if I add a few lines of comments the error message is printed after the comments and not after a specific instruction. I cannot provide a reproducible example because I do not know where exactly the error comes from. The error is the following: Error in names(frame)[names(frame) == "x"] <- name : names() applied to a non-vector I should specify that in my code I don't

Naming list elements in R

久未见 提交于 2019-12-03 18:58:45
问题 I've been doing some work with some large, complex lists lately and I've seen some behaviour which was surprising (to me, at least), mainly to do with assigning names to a list. A simple example: Fil <- list( a = list(A=seq(1, 5, 1), B=rnorm(5), C=runif(5)), b = list(A="Cat", B=c("Dog", "Bird"), C=list("Squirrel", "Cheetah", "Lion")), c = list(A=rep(TRUE, 5), B=rep(FALSE, 5), C=rep(NA, 5))) filList <- list() for(i in 1:3){ filList[i] <- Fil[i] names(filList)[i] <- names(Fil[i]) } identical

How to check if a string can be used as a variable name in PHP?

会有一股神秘感。 提交于 2019-12-03 15:09:54
In PHP one can use variable variables... For example... class obj { } $fieldName = "Surname"; $object = new obj(); $object->Name = "John"; $object->$fieldName = "Doe"; echo "{$object->Name} {$object->Surname}"; // This echoes "John Doe". However, $fieldName string may contain some characters not allowed in variable names. PHP will still create the field with that name (much like the associative array), but I will not be able to access it with $object->...... because it would not parse correctly. Now, is there any function that can check if the string can be used as a valid PHP variable name.