Assign unique value for duplicated rows

I want to assign the value for each duplicated row by ID in R df <- data.frame(ID=c(1,1,1,2,2,2,2,2,3,3,4), Code = c("A","A","A","B","B","C","C","D","A","A","C")) > df ID Code 1 1 A 2 1 A 3 1 A 4 2 B 5 2 ...
more »

2017-02-14 23:02 (2) Answers

parsing xml from a URL list

I have a list of URLs that direct to different xml files and I want to extract some info from them using R and the xml package. I am trying to do this with a for loop. I have this code but it gives me only the last xml (numtotal), how can I read al...
more »

2017-02-14 20:02 (1) Answers

saveRDS inflating size of object

This is a tricky one as I can't provide a reproducible example, but I'm hoping that others may have had experience dealing with this. Essentially I have a function that pulls a large quantity of data from a DB, cleans and reduces the size and loops ...
more »

2017-02-14 17:02 (0) Answers

ggplot2 - multiple plots scaling

I tried to generate multiple grid plots with ggplot2. So I would like to generate distribution plot with additional boxplot below x-axis and that for different groups and variables like that: CODE: I tried to do that with the following code : lib...
more »

2017-02-14 09:02 (1) Answers

Calculate a Lagged column on itself

I'm certain there is an easier way to accomplish this. I have the following dataframe: B <- c(1, 1, 1, 0, 1, 2, 2, 0, 0, 0) A <- c(1:10) df <-,B)) What I would like to do is add a third column (C) that applies col...
more »

2017-02-14 00:02 (0) Answers

Recursive Grouping in R

I am trying to find a way to create sequential Group_IDs based on "overlapping" variables. The easiest way for me to describe this is using a house, loan, and borrower example. Assume we have the following example df <- data.frame(house = c(...
more »

2017-02-13 20:02 (2) Answers

String/Text matching from two lists in R

I am new to this site and programming. So please correct me if I am wrong. I have two lists. List A and list B. I would like to match List A with List B. Both the list consist of 2,000 entries. I am just taking 3 entries to illustrate my requirement....
more »

2017-02-13 11:02 (0) Answers

NULL type of object in R

I am still a novice user in R, and have been reading Advanced R by Hadley to improve my R programming skills. I came across this code in his book: NULL>0 The output for this code is logical(0). I have two questions on this: Question 1: Wha...
more »

2017-02-13 09:02 (1) Answers

R syntax for Seurat ClassifyCells command

I am working with an R package called Seurat for single cell RNA-Seq analysis. I want to use a function of the package called ClassifyCells to add information about my various cell types to the data. But I am struggling to get the syntax correct wi...
more »

2017-02-12 21:02 (0) Answers

Conditional math between rows in data table

I have the following data table: library(data.table) dt = data.table(structure(list(var = c("rn_24", "rn_24", "albedo", "albedo", "et", "et", "gpp_g", "gpp_g", "ndvi", "ndvi"), land.use = c("lu1", "lu2", "lu1", "lu2", "lu1", "lu2", "lu1", "lu2", ...
more »

2017-02-11 23:02 (3) Answers

R Vector Values Overwrite in Function

specific problem i'm solving: Create a character vector with length of number-of-rows-of-iris-dataset, such that, each element gets a character value – “greater than 5″ if the corresponding ‘Sepal.Length’ > 5, else it should get “lesser...
more »

2017-02-11 21:02 (1) Answers

Creating summary table of user event data

Edit 2: I realized I can use dcast() to do what I want to do. However I do not want to count all of the events in the Event Data, only those that happened before a date specified in another data set. I can't seem to figure out how to use the subset a...
more »

2017-02-10 14:02 (2) Answers

Simulating Data Efficiently with data.table

I am trying to simuate a new dataset from two smaller datasets. It is important for me to maintain the marginal counts from these smaller datasets in the final dataset. Hopefully this reproducible example should explain what I mean. Build fake data ...
more »

2017-02-09 22:02 (0) Answers