named

How to add a named vector as a row to a data frame, reordered according to column name order?

一世执手 提交于 2019-12-01 20:09:50
How to add a named vector to a data frame, with the components of the vector reordered according to the column names of the data frame? I need to build a data frame one row at a time. A named vector is obtained by some processing and it provides the values for the row to be inserted. Problem is the named vector doesn't have components in the same order as data frame columns. This makes rbind produce wrong result. Here is the very simplified sample code: df = data.frame(id=1:2, va=11:12, vb=21:22, vc=31:32) v1 = c(id=4, va=14, vb=25, vc=NA) df = rbind(df, v1) So far, so good as this produces

Can a C# named Tuple be used as an MVC page model type?

人走茶凉 提交于 2019-12-01 04:15:05
In C# 7 you can have named tuples: var foo = (Name: "Joe", Age: 42); If I pass this to a MVC model using: return View(foo); Then what syntax should be used in the cshtml file to declare the model? Although this doesn't work, something like... @model (string Name, int Age); As for current time you can't and need to use @model Tuple<string, int> //or @model ValueTuple<string, int> For the difference between the two options: What's the difference between System.ValueTuple and System.Tuple? You can follow on GitHub: Razor throws CompilationFailedException when iterating over named Tuple (I know it

Injecting a named String using CDI

Deadly 提交于 2019-12-01 01:20:19
问题 I want to have a configuration parameter injected this way: public class MyManagedBean { @Inject public MyManagedBean(@Named("user") String user){ .... } } So I tried to implement a producer method this way: @ApplicationScoped public class MyConfiguration { private Properties loadProperties() { Properties properties = new Properties(); try { properties.load(getClass().getResourceAsStream( "user.properties")); } catch (IOException e) { throw new RuntimeException(); } return properties; }

Creating a named list from two vectors (names, values)

孤者浪人 提交于 2019-11-30 01:18:08
Is there a way to use mapply on two vectors to construct a named list? The first vector would be of type character and contain the names used for the list while the second contains the values. So far, the only solution I have is: > dummyList = list() > addToList <- function(name, value) { + dummyList[[name]] <- value + } > mapply(addToList, c("foo", "bar"), as.list(c(1, 2)) $foo `1` $bar `2` This seems like a rather contrived solution, but I can't figure out how to do it otherwise. The problems I have with it are: It requires the creation of dummyList even though dummyList is never changed and

What is the default scope of a Named CDI bean?

…衆ロ難τιáo~ 提交于 2019-11-29 01:10:39
Is there any default scope for a @Named CDI bean without additional @...Scoped annotations? I have not found any relevant information in the official Weld documentation . A @Named bean can be accessed over JSF without additional annotations, so some implicit scope seems likely. Thank you The default scope is the dependent pseudo-scope @Dependent , as stated in the weld documentation : CDI features the so-called dependent pseudo-scope. This is the default scope for a bean which does not explicitly declare a scope type. [...] An instance of a dependent bean is never shared between different

Creating a named list from two vectors (names, values)

ぃ、小莉子 提交于 2019-11-28 22:06:39
问题 Is there a way to use mapply on two vectors to construct a named list? The first vector would be of type character and contain the names used for the list while the second contains the values. So far, the only solution I have is: > dummyList = list() > addToList <- function(name, value) { + dummyList[[name]] <- value + } > mapply(addToList, c("foo", "bar"), as.list(c(1, 2)) $foo `1` $bar `2` This seems like a rather contrived solution, but I can't figure out how to do it otherwise. The

What is the default scope of a Named CDI bean?

試著忘記壹切 提交于 2019-11-27 15:41:41
问题 Is there any default scope for a @Named CDI bean without additional @...Scoped annotations? I have not found any relevant information in the official Weld documentation. A @Named bean can be accessed over JSF without additional annotations, so some implicit scope seems likely. Thank you 回答1: The default scope is the dependent pseudo-scope @Dependent , as stated in the weld documentation: CDI features the so-called dependent pseudo-scope. This is the default scope for a bean which does not

Combine/merge lists by elements names

烈酒焚心 提交于 2019-11-27 04:13:14
I have two lists, whose elements have partially overlapping names, which I need to merge/combine together into a single list, element by element: > lst1 <- list(integers=c(1:7), letters=letters[1:5], words=c("two", "strings")) > lst2 <- list(letters=letters[1:10], booleans=c(TRUE, TRUE, FALSE, TRUE), words=c("another", "two"), floats=c(1.2, 2.4, 3.8, 5.6)) > lst1 $integers [1] 1 2 3 4 5 6 7 $letters [1] "a" "b" "c" "d" "e" $words [1] "two" "strings" > lst2 $letters [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" $booleans [1] TRUE TRUE FALSE TRUE $words [1] "another" "two" $floats [1] 1.2 2.4 3.8

How do I extract just the number from a named number (without the name)?

时间秒杀一切 提交于 2019-11-26 22:04:34
I am looking for just the value of the B1(newx) linear model coefficient, not the name. I just want the 0.5 value. I do not want the name "newx". newx <- c(0.5,1.5.2.5) newy <- c(2,3,4) out <- lm(newy ~ newx) out looks like: Call: lm(formula = newy ~ newx) Coefficients: (Intercept) newx 1.5 1.0 I arrived here. But now I am stuck. out$coefficients["newx"] newx 1.0 For a single element like this, use [[ rather than [ . Compare: coefficients(out)["newx"] # newx # 1 coefficients(out)[["newx"]] # [1] 1 More generally, use unname() : unname(coefficients(out)[c("newx", "(Intercept)")]) # [1] 1.0 1.5

Combine/merge lists by elements names

。_饼干妹妹 提交于 2019-11-26 11:05:42
问题 I have two lists, whose elements have partially overlapping names, which I need to merge/combine together into a single list, element by element: > lst1 <- list(integers=c(1:7), letters=letters[1:5], words=c(\"two\", \"strings\")) > lst2 <- list(letters=letters[1:10], booleans=c(TRUE, TRUE, FALSE, TRUE), words=c(\"another\", \"two\"), floats=c(1.2, 2.4, 3.8, 5.6)) > lst1 $integers [1] 1 2 3 4 5 6 7 $letters [1] \"a\" \"b\" \"c\" \"d\" \"e\" $words [1] \"two\" \"strings\" > lst2 $letters [1] \