Gistlib Logo

gistlib

create a new column from a dataframe that returns the minimum number in another column and ignores na in r

# Assuming data frame is named df with columns "col1" and "col2"
df$new_column <- apply(df, 1, function(x) min(x, na.rm = TRUE))
129 chars
3 lines

similar r code snippets

export csv in dataframe, remove specific rows and column in r
remove specific columns in a dataframe in r
export df as csv in r
delete empty rows in r
sort a dataframe according to a specfic variable pattern in r
create a loop based on columns varaibles in r
create a loop in specific columns from a dataframe in r
filter a dataframe from a specific value in a column in r
remove columns in a dataframe in r
recode some rows of dataframe in r

related categories

r
dataframe
na

gistlibby LogSnag