logo
down
shadow

how to set two variables for the same column?


how to set two variables for the same column?

By : user3099631
Date : January 11 2021, 03:34 PM
will help you suppose i have the following statement , This is the right syntax:
code :
SET [size] = '$($newSize.Size) $($newSize.Unit)'


Share : facebook icon twitter icon
R: Sum column wise value of two/more data frames having same variables (column names) and take Date column as reference

R: Sum column wise value of two/more data frames having same variables (column names) and take Date column as reference


By : Astor yeung
Date : March 29 2020, 07:55 AM
To fix this issue I want to sum two data frames having similar columns and take Date column as a reference. Eg: , You can consider the following base R approach.
code :
df3 <- cbind(df1[1], df1[-1] + df2[-1])
df3
        Date V1 V2 V3
1 2017/01/01  3  7 11
2 2017/02/01  8 12 14
library(dplyr)
df3 <- bind_rows(df1, df2) %>%
  group_by(Date) %>%
  summarise_all(funs(sum))
df3
        Date    V1    V2    V3
       <chr> <int> <int> <int>
1 2017/01/01     3     7    11
2 2017/02/01     8    12    14
library(data.table)
df_bind <- rbindlist(list(df1, df2))
df3 <- df_bind[, lapply(.SD, sum), by = Date]
df3
         Date V1 V2 V3
1: 2017/01/01  3  7 11
2: 2017/02/01  8 12 14
df1 <- read.table(text = "Date    V1    V2    V3  
'2017/01/01' 2    4    5   
'2017/02/01' 3    5    7",
                  header = TRUE, stringsAsFactors = FALSE)

df2 <- read.table(text = "Date    V1    V2    V3  
'2017/01/01'    1    3     6  
                  '2017/02/01'    5    7     7",
                  header = TRUE, stringsAsFactors = FALSE)
How to rename column with dplyr where both the new column name and the original column name are variables

How to rename column with dplyr where both the new column name and the original column name are variables


By : Assyrianlegend
Date : November 05 2020, 04:01 AM
Hope this helps This kind of question is difficult to search for here, though I've tried. , The link provided offered insight to the solution
code :
rename_data <- function(iris, target = "Species", new_target_name = "Spec3") {
  iris2 <- iris %>% rename(!!new_target_name := target)
  iris2
}

head(rename_data(iris))
creating, directly, data.tables with column names from variables, and using variables for column names with :=

creating, directly, data.tables with column names from variables, and using variables for column names with :=


By : Muskaan
Date : March 29 2020, 07:55 AM
Hope this helps For the first question, I'm not absolutely sure, but you may want to try and see if fread is of any help creating an empty data.table with named columns.
As for the second question, try
code :
DT[, c(nameOfCols) := 10]
Make a list from a dataframe: column A are variables and column B are associated with values in column C

Make a list from a dataframe: column A are variables and column B are associated with values in column C


By : BLK
Date : March 29 2020, 07:55 AM
help you fix your problem I've kind of hammered this into place, but this should do what you're asking. I'm going back to clunky for loops here, but could be adapted with lapply to be more efficient i'm sure.
code :
outlist <- list()
for(i in unique(df$year)){

  for(j in unique(df$item)){

    list.item.name <- paste(j,i,sep='.')

    tdf <- df[which(df$year==i & df$item==j),c('node','value')]
    newdf <- data.frame(t(tdf))
    names(newdf) <- newdf$node
    rownames(newdf) <- NULL

    outlist[[list.item.name]] <- newdf

  }

}
> outlist
$`litter.2010`

1 lost pot pool
2   50  15   35

$lost.2010

1 pool pot lost
2   30  10   60

$bin.2010

1 collected uncollected
2        96           4

$uncollected.2010

1 litter burn dump
2     25   55   20

$collected.2010

1 litter dump recycle burn
2    3.7 54.3    30.0 12.0

$litter.2011

1 lost pot pool
2   50  15   35

$lost.2011

1 pool pot lost
2   30  10   60

$bin.2011

1 collected uncollected
2        96           4

$uncollected.2011

1 litter burn dump
2     25   55   20

$collected.2011

1 litter dump recycle burn
2    3.7 54.3    30.0 12.0

$litter.2012

1 lost pot pool
2   50  15   35

$lost.2012

1 pool pot lost
2   30  10   60

$bin.2012

1 collected uncollected
2        96           4

$uncollected.2012

1 litter burn dump
2     25   55   20

$collected.2012

1 litter dump recycle burn
2    3.7 54.3    30.0 12.0
script a dynamic code to insert values into variables and also variables are the column names

script a dynamic code to insert values into variables and also variables are the column names


By : user3229039
Date : March 29 2020, 07:55 AM
To fix this issue Trigger is what you are looking for.
You need to create a before insert trigger to calculate the value of gst.
code :
delimiter $$
CREATE TRIGGER `calc_gst`
 BEFORE INSERT
 ON `sales`
 FOR EACH ROW
 BEGIN
   set new.gst = new.gross_sales*0.07;
 END
delimiter ;
insert into sales values('inv-1',0,100);
Related Posts Related Posts :
  • Calculate the row value based on different formula
  • Debezium Error : ConnectException: Data row is smaller than a column index
  • TSQL -- find records in table with multiples in one column, and at least one specific occurrence of a value in another c
  • Table-Valued Parameter Recieving Invalid Data Type Error
  • UPDATE PERMISSION without ALTER permission
  • How to determine a table's dependencies?
  • Creating Dynamic Pivot Table Column Names
  • How to debug CLR database object (stored procedure) using Visual Studio 2019
  • Split BulkColumn into Rows
  • Naming a Column using Variable
  • T-SQL Slowly Changing Dimension - Multiple Updates, Single Action Output?
  • SQL Output as XML namespace
  • Using Wildcard For Range of Characters In T-SQL
  • Azure SQL Server Elastic query with ApplicationIntent ReadOnly
  • How to get date ranges according to date data inside database table
  • How to get those records that contains every items mentioned in where clause
  • SQL Trigger on insert, only for new rows
  • Recursively replace string using a CTE
  • How to merge multiple column into one column with same table in SQL Server?
  • Designing stored procedure to work with Multiple Tables which have different formats and logic
  • How to select SQL Server table as tab delimited string
  • How to delete specific range of records from a GROUP BY query?
  • SAS dsnless connection to SQL server not working even if OLEDB is installed
  • How to correct an error in SELECT statement
  • All cases when check constraints are executed for each row
  • Exporting database data to csv in classic asp
  • Why does this char value not convert to datetime?
  • How to get file type from binary data in SQL Server File table?
  • Reading derived column expression
  • How do I persist sales price in an orders details table?
  • How to extract data from xml nodes as table from column?
  • Removing Leading and Trailing Zeros along with a Case
  • How to insert new line Char(13) in T-SQL
  • Get first date record from multiple records
  • SQL Server Procedure Returning -1
  • Underscore in Where clause yields unexpected result, why?
  • How to calculate the SID for new logins?
  • Purpose of defining parameters in Access query
  • Windows API call "RegGetValueW" returned error code: 0
  • How to convert CURSOR based query in to SET based
  • Why my main query is running successfully at the same time as subquery returns an error?
  • Rounding up starting 6
  • How to use INSERT INTO OPENROWSET to export to Excel without being an admin on the target server
  • SQL SERVER job is not executing SSIS
  • How to convert Row by row execution in to SET based approach in SQL
  • How to copy databases automatically from one server to another in efficient way (not backup and restore)
  • How to combine rows of similar results into one?
  • Convert HH:MM TT to Time and append onto date
  • Dynamic stored procedure to update a table
  • How do you debug or step through the code in SQL Server Management Studio 18?
  • How to import .bak file into SQL Server?
  • SQL Server Wildcard Length
  • SQL Server : column data extraction
  • The nullability property of arithmetic operators over floating point data type in SQL Server
  • MD5 Hashing in SQL Server
  • How to extract every 7 characters of an nvarchar into another table?
  • ARX Anonymization Tool - supported databases
  • What are good practices for granting database permissions to a web service connection?
  • Go MSSQL Connection
  • SQL Server select query very slow
  • shadow
    Privacy Policy - Terms - Contact Us © festivalmusicasacra.org