Geting new data into old data frame in R

Geting new data into old data frame in R

Content Index :

Geting new data into old data frame in R
Tag : r , By : user183676
Date : November 27 2020, 04:01 AM

Does that help We could use a data.table join on the 'OD' and assign (:=) the 'F3' column values in 'new' (i.F3) to the 'F3' column in 'old'
new$F3 <- as.integer(new$F3) # as the class for old 'F3' is `integer`
setDT(old)[new, F3 := i.F3, on = .(OD)]
#   O D F3  OD
#1: I I  1 I I
#2: A F 16 A F
#3: B C  3 B C
#4: D B  0 D B
#5: R D 13 R D
#6: F G 14 F G
#7: A B  7 A B

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

How to sort data in a data frame and then access data in a data frame, by indexing by date?

Tag : r , By : Kilimanjaro
Date : March 29 2020, 07:55 AM
this will help Assuming you have a time series of numbers indexed by unique dates, read.zoo in the zoo package does most of that. Read the 5 vignettes that comes with it as well as ?read.zoo and in particular the zoo-read vignette.

Get row indices of data frame A according to multiple matching criteria in that data frame and another data frame, B

Tag : r , By : Schmidt
Date : March 29 2020, 07:55 AM
I hope this helps you . Let's say we have two data frames in R, df.A and df.B, defined thus: , 1) Using SQL it can readily be done in one statement:

sqldf('select a.rowid
       from "df.B" b 
       left join "df.A" a on obs_min >= bin_min and obs_max <= bin_max')

1      4
2     NA
3      5
4      2
5     NA
6      4
7      3
8      4
9      5
10     2
m <- merge(df.B, df.A)
stack(by(m, as.numeric(sub(".*_", "", m$obs_ID)), 
      with, c(which(obs_min >= bin_min & obs_max <= bin_max), NA)[1]))
   values ind
1       4   1
2      NA   2
3       5   3
4       2   4
5      NA   5
6       4   6
7       3   7
8       4   8
9       5   9
10      2  10
sapply(1:nrow(df.B), function(i)
  c(which(df.A$bin_max >= df.B$obs_max[i] & df.A$bin_min <= df.B$obs_min[i]), NA)[1]) 
[1]  4 NA  5  2 NA  4  3  4  5  2
mapply(function(x, y) c(which(x >= df.A$bin_min & y <= df.A$bin_max), NA)[1], 
seq_len(nrow(df.A)) %*% 
  (outer(df.A$bin_max, df.B$obs_max, ">=") & outer(df.A$bin_min, df.B$obs_min, "<="))
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    4    0    5    2    0    4    3    4    5     2

Want to create new data frames in R by subsetting a data frame in a loop and assign each data frame name based on i valu

Tag : r , By : KaoFloppy
Date : March 29 2020, 07:55 AM
hop of those help? Using the same split function as Mark, if it is important for you to save each of the resulting dataframes into your environment, you can use the "list2env" function.
df <- data.frame(
    month = rep(c("Jan","Mar","Apr"), 4)
    , somevalue = runif(12)
groups <- unique(df$month)

newdf_list <- split(df, f = df$month)
list2env(setNames(newdf_list, groups), .GlobalEnv)

Compare two data.frames to find the rows in data.frame 1 and data.frame 2 which have equal values in selected columns

Tag : r , By : Ray
Date : March 29 2020, 07:55 AM

Converting data.frame to data.table, perform calculation, back to data.frame, rest of script malfunctions?

Tag : r , By : µilad
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
  • Unable to use has_goog_key() in R
  • how to multiply each row with a scaler in corresponding column?
  • R is not recognizing levels of a factor as the same. Is there a way to do this?
  • Calculating mean of replicate experiment result values in a column based on multiple columns using R
  • Best method to extract the first instance of a string between specified keywords using data.table
  • ignore optional combination of alphanumeric characters in str_extract
  • Why tracemem shows two copies when modification occurs inside function body?
  • Can't use mppm on multitype point patterns
  • How to move selected matrix rows to top of matrix based on a selection vector of row names
  • Combining expressions with a common operator
  • Passing string through multiple filters for matching
  • Convert two columns in R to rows of unique occurrence
  • How to create a dataframe using a function based on user-input?
  • How to access the visited vertices in a given shortest path using R igraph
  • Differences in Unicode character output with print()
  • Extracting Function or Objects from a String and then Piping Them with Magrittr/Dplyr
  • renderUI not evaluated until it is rendered
  • Find the maximum absolute value by row in an R data frame
  • Extracting data from irregular lists using purrr:map()
  • transforming data based on range of column in r
  • Identify and subset rows with some similar information
  • converting character from mongolite to timestamp in R
  • Create list from two vectors with every combo of each
  • Error in running a spread because of unique 'key combinations'; combining rows of data
  • visualize numerical strings as a matrixed heatmap
  • how to make a blocked matrix?
  • How to summarize with two functions using with dplyr
  • Dataframe is no longer the same after being saved to Excel and read back in
  • Create duplicate rows using based on availability of data
  • Keep empty groups when grouping with data.table in R
  • Grouping of Event Time Data based on multiple, iterative conditions
  • Formatting Numbers in Flextable for Specific Columns
  • How to store results from for-loop into a dataframe
  • How to select the values in my dataframe which has logical operator "<" (less than), divide them by two, an
  • Rowwise extract data between two strings
  • Convert a string separate by . and +
  • stacking function for values in R
  • dplyr coerces characters to factors
  • How do I use spread and group_by on a single row dataset
  • Replacing values in one matrix with values from another
  • Aggregate data and exclude duplicates in one column
  • Perform an R data.table binary search with OR select
  • How can I include a function in the Standard Deviation parameter of pnorm
  • How to get a tidy excel output of P values from R
  • Rotate boxplot legend (R, ggplot2)
  • dplyr::n() returns “Error: Error: n() should only be called in a data context ”
  • Extract fix columns and one variable column from a list of df´s in R
  • A function that can translate DNA sequence to binary code
  • I want to extract 365 netcdf files using loop
  • rvest vs RSelenium results for text extracting
  • Converting wide data to tall data
  • How to remove vertical white lines when using ggsave in R?
  • R-Shiny error: "renderDataTable" and "server=FALSE"
  • Read csv file with selected rows using data.table's fread
  • how to resolve an error like non numeric argument to binary argument?
  • If value exists in environment
  • R get one value according to some rules in each group
  • Use any apply method to find difference between max and min score for each students
  • subsetting a dataframe by existing object
  • Parsing time formats in R
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com