following should do the trick
cbind(id = x[, 1], x[, -1]/rowSums(x[, -1]))
## id val0 val1 val2
## 1 a 0.08333333 0.3333333 0.5833333
## 2 b 0.13333333 0.3333333 0.5333333
## 3 c 0.16666667 0.3333333 0.5000000
More Related Contents:
- Remove columns from dataframe where ALL values are NA
- R Apply() function on specific dataframe columns
- apply a function over groups of columns
- rbind data frames based on a common pattern in data frame name
- Dataframe create new column based on other columns
- Last Observation Carried Forward In a data frame? [duplicate]
- use multiple columns as variables with sapply
- Count number of rows within each group
- Drop unused factor levels in a subsetted data frame
- Why is it not advisable to use attach() in R, and what should I use instead?
- Create an empty data.frame
- Subset data frame based on multiple conditions [duplicate]
- R – Concatenate two dataframes?
- How to convert dataframe into time series?
- Merge unequal dataframes and replace missing rows with 0
- Is there a R function that applies a function to each pair of columns?
- Removing display of row names from data frame
- How to delete rows from a data.frame, based on an external list, using R?
- Split one row into multiple rows [duplicate]
- Converting a list of data frames into individual data frames in R [duplicate]
- Shift values in single column of dataframe up
- finding close match from data frame 1 in data fame 2
- Combine several data frames in the global environment by row (rbind)
- Extract text after “/” in a data frame column
- Deleting specific rows from a data frame
- Reshape a dataframe to long format with multiple sets of measure columns [duplicate]
- Count number of non-NA values for every column in a dataframe [duplicate]
- Count unique values for every column
- What you can do with a data.frame that you can’t with a data.table?
- Override column types when importing data using readr::read_csv() when there are many columns