Questions tagged [mutate]
426 questions
0
votes
1 answer
How to select the first value in a row going backward in columns that isnt NA
My dataframe is the following:
wave <- data.frame(ID=c(1, 2, 3, 4, 5, 6),
income_wave_1_2017=c(109, 106, NA, 10, 65, NA),
income_wave_2_2018=c(NA, 108, 66, NA, NA, 190),
…

Max Herre
- 47
- 5
0
votes
2 answers
Create new column based on pattern in other column
I have the following data frame in R out of which I'd like to create a new column containing the Nut for each municipal (See second table). "Nut" refers simply to a higher hirachy level of municipalities in portugal. For later analysis I need to…

Fabio
- 21
- 2
0
votes
1 answer
How to bring several dataframes from different waves together by a function?
the following problem occured in my work with a longitudinal dataframe.
There are several waves (years) in the study. In every wave there is an identification number (ID) for the same person and in addition some variables of interest that I want to…

Max Herre
- 47
- 5
0
votes
2 answers
Filling a column with conditions and formulas
I am working on calculating the area of flowering parts in certain plots. However, different types of plants have different types of measurements (for example, some flowers, we have the size of the whole inflorescence and some we have only the size…

KNieder
- 25
- 5
0
votes
0 answers
R Studio: Mutating a column variable based on two selection conditions
The dataframe above represents a repeated-measures design, each participant took part in both task A and B. The condition determines which order the tasks occurred - if in condition 1, then Task A came first followed by task B, and vice-versa for…

Anthony
- 1
- 1
0
votes
0 answers
Creating new column based on two selection conditions
Subject ID Condition Task A Task B First Task
1001 1
1002 2
1003 1
This is a within-subjects design. Each participant took part in tasks A and B, however, the order in which the tasks were presented (first or second)…

Anthony
- 1
- 1
0
votes
0 answers
R mutate function mixing up variables
I am doing an introductory R assignment for one of my stats classes, and I am having some difficulty with the mutate function from tidyverse. When I first used it to convert my gender variable to a factor it worked fine, but then when I tried to use…
0
votes
2 answers
Formatting date column with different formats (including missing day information) - lubridate
I'm relatively new to R. I downloaded a dataset about clinical trial data, but it occurred to me, that the format of the dates in the relative column are mixed up: most of them are like "September 1, 2012", but some are missing the day information…

c_dinosaur
- 3
- 2
0
votes
0 answers
I want to move only some elements of a row to an adjacent column
I'm sorting out taxa.
The data in the Taxon column was sorted by placing k in the Kingdom column, p in the Phylum column, and c in the Class column.
And I deleted k__, p__ and c__.
Most have been successful, but some have not.
I marked the problem…

SW Lee
- 1
- 1
0
votes
1 answer
mutate and if_any with condition over multiple columns
I tried to combine mutate, case_when and if_any to create a variable = 1 if any of the variables whose name begins with "string" is equal to a specific string.
I can't figure out what I'm missing in the combination of these conditions.
I'm…

ggg
- 73
- 1
- 7
0
votes
0 answers
Add column in a data set in R
I have an existing data frame with these columns. The home teams played against the Away Team in the sequence mentioned. In Results column H denotes that Home Team won, P denotes AwayTeam won and D denotes that it was a draw.
HomeTeam = Liverpool,…

IAwa
- 5
- 3
0
votes
1 answer
How to create new columns in a new data frame from information in an existing data frame in R
I have an existing data frame with these columns. The home teams played against the Away Team in the sequence mentioned. In Results column H denotes that Home Team won, P denotes AwayTeam won and D denotes that it was a draw.
HomeTeam = Liverpool,…

IAwa
- 5
- 3
0
votes
2 answers
Combine two columns in one in R without duplication
I have a data frame with two columns below:
HomeTeam AwayTeam
Zimbabwe Kenya
Netherlands Zimbabwe
Kenya Amsterdam
I want to create a column Team from both these column but it shouldn't repeat the name of the team. How do I go about…

IAwa
- 5
- 3
0
votes
1 answer
Updating all columns of a table dependent on a single column
I have a table that consists of only columns of type Date. The data is about shopping behavior of customers on a website. The columns correspond to the first time an event is triggered by a customer (NULL if no occurrence of the event). One of the…

alexT
- 49
- 5
0
votes
0 answers
Logstash Grok Pattern, mutate
i ran into a problem.
i have a pipeline:
input {
tcp {
host => "10.10.10.10"
port => "5959"
codec => "json"
type => "my_type"
mode => "server"
}
}
filter {
if [type] == "my_type" {
grok {
…

Aleksandr
- 41
- 1
- 3