spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

applying melt in a loop


Try

library(reshape2)
set <- 'A'
res <- transform(do.call(`rbind`,lapply(lst,
melt)), set=set)
row.names(res) <- NULL

Suppose, you have multiple elements in set (length equal to length of lst) and want to create a new column in each list element for the corresponding set element

set <- LETTERS[1:3]
res1 <- do.call(`rbind`,Map(cbind, lapply(lst,
melt), set=set))
row.names(res1) <- NULL
head(res1,3)
#   Var1   Var2 value set
#1    1 line 1    NA   A
#2    2 line 1    NA   A
#3    3 line 1    NA   A

data

lst <- structure(list(EcEcDelta =
structure(c(NA, NA, NA, 4183.9897, 
4197.9263, 4169.5312, 4164.3252, 4413.3159,
4396.481, 4155.8994, 
4110.7871, 4296.3462, 4497.458, 4516.624,
4597.8345, 4680.0024, 
4800.0811, 4992.167, 5375.4189, 5933.1914,
6589.8003, 7691.2852, 
8650.3418, 8643.0215, 7475.228, 6215.3271,
5240.209, 4646.1699, 
4358.4946, 4203.7007, 4200.9126, 4292.7974,
4290.2119, 4035.3877, 
3824.6089, 3694.5603, 3794.0649, 3835.3845,
3743.8027, 3839.2417, 
3944.7722, 3975.55, 3994.0811, 4193.9482,
4220.0361, NA, NA,NA),
.Dim = c(4L, 12L), .Dimnames = list(NULL,
c("line 1", "line 2", "line 3", "line 4", "line
5", 
"line 6", "line 7", "line 8", "line 9", "line 10",
"line 11", 
"line 12"))), MesecMesecDelta =
structure(c(4708.2158, 4678.9521, 
4674.4448, 4747.0122, 4717.1528, 4855.1533,
4823.2969, 4729.3257, 
4474.9043, 4478.2461, 4659.1538, 4626.4385,
4698.3784, 4795.8794, 
4914.1973, 5186.6772, 5517.021, 5717.6484,
6304.8179, 7310.9424, 
8474.2725, 9362.792, 9325.4678, 8488.7021,
7503.6167, 7087.0112,  
4211.4683, 4333.1514, 4346.751, 4350.1226,
4115.3848, 3880.6357, 
3890.1731, 3747.5061, NA, NA, NA, NA, NA, NA, NA,
NA), .Dim = c(6L, 
7L), .Dimnames = list(NULL, c("line 1", "line 2",
"line 3", "line 4", 
"line 5", "line 6", "line 7"))), MesecMesDelta =
structure(c(NA, 
NA, 4407.7998, 4471.9248, 4581.3101, 4618.3403,
4529.812, 4604.5894, 
4775.9009, 4824.9214, 4684.2368, 4594.7852,
4447.998, 4347.6182, 
4370.4023, 4211.9419, 4262.7798, 4381.9023,
4452.2407, 4653.1538, 
4997.3403, 5659.2056, 6694.8037, 7665.9014,
7676.9712, 7077.6855, 
3600.1545, 3739.146, 3968.1042, 4155.644,
4273.3623, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 3955.3906,
3826.8286, 
3217.3462, 3034.8352, 2965.7563, 3042.1465,
3121.8101, 3150.625, 
3139.7209, 3178.7612, 3373.1699, 3699.7705,
3920.2891, 3914.2915, 
NA, NA, NA), .Dim = c(5L, 12L), .Dimnames = list(
NULL, c("line 1", "line 2", "line 3", "line 4",
"line 5", 
"line 6", "line 7", "line 8", "line 9", "line 10",
"line 11", 
"line 12")))), .Names = c("EcEcDelta",
"MesecMesecDelta", 
"MesecMesDelta")) 

Categories : R

Related to : applying melt in a loop
Applying CSS to img-tag-embedded SVG images
I do not think this is possible. You are correct in that using inline-SVG will allow you to manipulate the parts of the svg, but including it in an img tag will not. See http://css-tricks.com/using-svg/

Categories : HTML
XSL applying tags incorrectly
This is one possible stylesheet, merely sticking to the structure of the input XML document: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" version="4.0" /> <xsl:template match="objective"> <h4><xsl:value-of select="name" /></h4> <div><xsl:val

Categories : HTML
Applying a Variable to a DIV CLASS In PHP
This is an odd thing to do, as PHP can only generate the initial HTML source that the browser receives. You're basically saying "I need the box at 100/200 and 100/500". In a battle between CSS rules, the most specific rule wins. Normally that'd be style="..." but in this case you didn't add the px unit to the inline style so the browser rejects it as meaningless. The "quick fix" here is to simply

Categories : PHP
Applying keypress listener to all subelements
The keydown event supports event bubbling, so you can just add the handler to the container element like document.querySelectorAll('.container')[0].addEventListener('keydown', function(e) { console.log('keypressed', this, e); //e.target will refer to the actual event target log('down in `' + e.target.innerHTML + '` with keycode: ' + (e.keyCode)) }) function log(msg) { document.querySe

Categories : Javascript
Binding & CustomViewSource applying together in a datagrid wpf
I guess you want to bind to a property of your UserControl. 1) ensure your UserControl itself has a name (usually at the top of your xaml class): <UserControl x:Class="myNameSpace.MyUserControl" x:Name="MyUserCtrl1" ... 2) set binding <Image Source="{Binding ElementName=MyUserCtrl1, Path=ClaimImage}" .. /> Requirements: UserControl.DataContext created Cl

Categories : Wpf
Recently Add
How to make my loop run faster in R?
Can I create a POSIXct data.frame for a day, in minute units, for that day, each year, over 28 years?
Join and add columns in one go
Combine blocks of sp spatial data into a single block
How to customize a regression line in an R graphics XY scatterplot?
How to apply a function to factored subgroups in R?
R: What's wrong with my use of %in%?
R (data.table) group data by custom range (for example, -18, 18-25, ..., 65+)
Matrix specification for simple diagram, using 'diagram' package
R Match and compare values from different vectors
Build a vector/frame by combining regmatches results
interpreting R code function
how do I check whether a plot was written to file in R
Merging two data frames with different sizes by matching their columns
Using grid.layout inside grid.layout with grid package: weird impact of plotting order
R : adding a new column to an existing dataframe with a condition
Work in multiple environments in RStudio and R
using regex in ddply variables
Draw vertical quantile lines over histogram
Aggregate table with dates and geographic coordinates
Reading floats from a file in R
Use scientific notation with xtable in R
Displaying discrete character data on a phylogeny using R
generating random matrixes with genweb in a for loop
How to Use $ and | Logical operators together In R
How to extract / subset an element from a list with the magrittr %>% pipe?
Return attributes within given radius of observation in R
R cor across rows and columns
access that element in dataframe in R
Applying is.logical to a list with multiple data types
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.