# How do I get every character after a segment in my column in R?

Fake City, TX Court House I would like to return: Court House This is what I have from another post. I used it to be able to extract the city piece. gsub(",.*\$", "", COLUMN\$Entity) My gut tells me that ",.*\$ will have to change but I’m not sure what to change it to. I’m new… Read More How do I get every character after a segment in my column in R?

# Manipulating Single Values in R to Column values

I have imported some data provided by someone else from Excel. It’s pretty messy, so I’m trying to get it into shape for analysis, but the format of the code is making it difficult. Here is a minimal example of the data as it is: Contraption 1 Attempt 1 #s AX AY AZ Distance 3->6… Read More Manipulating Single Values in R to Column values

# Calculate the difference if the values in one column match

I have some longitudinal data where the obversions of some individuals are missing at some time points: df <- data.frame(id = c(1, 1, 1, 1, 1, 2, 2, 2), #id2 is missing for time 3 and 5 time = c(1, 2, 3, 4, 5, 1, 2, 4), value = c(3, 4, 2, 55, 5, 9,… Read More Calculate the difference if the values in one column match

# Pick the highest group/category for each person – python

I have a dataframe with three columns, Name, group1 and group2. The ‘Name’ column shows the different people/cases and both the ‘group’ columns shows the category these people belong too. Below is an image of how this data set looks: As we can see from the above data set, the same person can be assigned… Read More Pick the highest group/category for each person – python

# pandas dataframe generate rows

I have a Input dataframe: import pandas as pd # Define the input data data = { ‘ID’: [500, 200, 300], ‘A’: [3, 3, ”], ‘B’: [3, 1, ”], ‘C’: [2, ” ,”], ‘D’: [”, 2, 1], ‘E’: [”, ”,2 ], } # Convert the input data to a Pandas DataFrame df = pd.DataFrame(data) Input… Read More pandas dataframe generate rows

# case_when with three conditions update NA rows

I am populating a column based on other columns. The idea is: If column Maturity is NA (other values already filled based on tissue analysis), and if female/male with certain size put either Mature or Immature. Therefore I have the following code: data <- data %>% mutate(Sexual.Maturity = case_when( (Sexual.Maturity==NA & Sex== "M" & Length… Read More case_when with three conditions update NA rows

# combine the row with the different variable

i want to combining 2 dataframe but there are diferent variable example df1=data.frame(x1=c(1,1,1,2,2,2,2),x2=c("a","a","b","b","c","c","c"),x3=c("t","u","v","w","x","y","z"),x4=c("apple","apple","mango","mango","mango","mango","mango")) df2=data.frame(x1=c(1,1,1,2,2,2,2),x2=c("a","a","b","b","c","c","c"),x4=c("apple","banana","banana","melon","melon","melon","melon"),x5=c("t","u","v","w","x","y","z")) i’d tried with cbind, rbind, merge, right and left join, but no one can like I expected. my expectation in df is there 13 row and 5 column. why 13 column? because in row 1 can combined >Solution : You could… Read More combine the row with the different variable

# Remove vertical lines in ggplot

I am using some longitudinal data to make a line plot with ggplot2. The goal is to plot the data for each individual (Name) across time (Age). However, I don’t know why there are vertical lines shown in the plot: ggplot(sum_data, aes(x=Age,y=Turns,group=Name))+ geom_line() How do I remove those vertical lines? Thanks for any help! Here… Read More Remove vertical lines in ggplot

# Fill empty rows with values from other rows

I have a dataset with a number of cases. Every case has two observations. The first observation for case number 1 has value 3 and the second observation has value 7. The two observations for case number 2 have missing values. I need to write code to fill the empty cells with the same values… Read More Fill empty rows with values from other rows