Is there an R Function whrer i can combine multiple rows? [duplicate] - r

This question already has answers here:
Group by multiple columns and sum other multiple columns
(7 answers)
How to sum a variable by group
(18 answers)
Closed 2 years ago.
I have this table:
I want to combine the rows, so that the values off the variables are in one row from the same month.

Related

replacing a specific value in data frame [duplicate]

This question already has answers here:
Replace given value in vector
(8 answers)
How do I change a single value in a data.frame?
(4 answers)
How to change a single value in a data frame in R
(4 answers)
How to change a cell value in data.frame
(2 answers)
Closed 4 months ago.
I have the following data frame:
df <- data.frame(
item=c("a","","a","d","e"),
price_today=c(1,2,"THREE%%",4,"SIX/SIX"))
If I would like to select "THREE%%" and "SIX/SIX" in column price_today and convert them to "3?3" and "6?6", respectively, how should I go about it?

Get the average for each 4 rows [duplicate]

This question already has answers here:
How to get the sum of each four rows of a matrix in R
(3 answers)
Average of n rows
(1 answer)
Closed 8 months ago.
I have a column with hundreds of values, I want to get the average for each 4 rows, then I move to another four rows, etc. How could I write that loop in R studio, I attached here a simple example, what should I do if I have NA values, how to consider those values as zeros?

How to drop multiple columns with similar names in a data frame [duplicate]

This question already has answers here:
How to drop columns by name pattern in R?
(6 answers)
Remove columns that contain a specific word
(5 answers)
Closed 3 years ago.
My data set has about 100 columns and some of them (about 25) are called similar but not them same. I'd like to delete all columns that start with "reads_per_million" because write this is so impractical:
data_tumor <- data_tumor[,-c(3,5,7,13,15,22,33,54,65,34,**etc,etc**)]
Thank you so much

Sum values for a specific period [duplicate]

This question already has answers here:
R data.table sum of group subset using dates
(3 answers)
Count rows since a date condition is met
(2 answers)
Count number of rows in window around timestamp
(3 answers)
Closed 4 years ago.
I have some IDs, dates and Values.
I want to sum values for each ID for the last 10 days.
This code can reproduce my dataset:
date<-as.Date(c("05/03/2017","05/10/2017","05/14/2017","05/19/2017","05/22/2017"),format="%m/%d/%Y")
value<-rpois(20,50)
id<-NULL
for(i in 1:4){id<-c(id,rep(i,5))}
mydata<-data.frame(id,date=rep(date,4),value)
So, the output would be the dataset above with a new column. This column would have the sum of values of lasts 10 days.
Thanks in advance.

The most efficient way to calculate numbero of unique values in vector [duplicate]

This question already has answers here:
How to count the number of unique values by group? [duplicate]
(1 answer)
Unique values in each of the columns of a data frame
(9 answers)
Closed 5 years ago.
Is there better way to compute this instead of:
length(unique(vector))
let's assume that we donno what class is the vector.
You can use
library(data.table)
vector <- c(1,2,2,2,3)
uniqueN(vector)

Resources