0

I have a dataframe shown below (df <- read_csv("~/data.csv"):

gene_id         a       b
abc100.12       30      70
abc101.23       40      80
abc102.345      50      90
abc103.4567     60      100

I want to make change this dataframe like below:

gene_id         a        b
abc100         30        70
abc101         40        80
abc102         50        90
abc103         60        100

Basically, I want to drop decimal values in gene_id column and keep everything else the same. If the original dataframe is df (df <- read_csv("~/data.csv")), how can I write a R code so that I have a dataframe shown above?

lmo
  • 37,904
  • 9
  • 56
  • 69
user7755336
  • 227
  • 2
  • 9

1 Answers1

0

Use this script to replace the values after decimal with blank:

rownames(df) <- gsub("\\..*", "", rownames(df))

if the gene_id is assigned to row names.

Farshad
  • 51
  • 3
  • You’re assigning that to colnames? – Dodge May 01 '18 at 23:51
  • The data was in raw format, not tabular, and it seemed to me that the values are column names. The question is now edited. I corrected my answer to reflect the change. Thank you for the note! – Farshad May 02 '18 at 00:01