简体   繁体   中英

R: how to make a column in a dataframe not recognized as a variable

I have a dataframe in R with 5 columns. The first column contains the row names, but R is recognizing this as a variable so this is throwing errors for me in subsequent steps. Any ideas on how to make R recognize that these are rownames and not a variable? Many thanks for all the help!

**I am doing some gene sequencing analysis, and the dataframe contains the clinical information. As such, I would prefer to keep the dataframe intact since the rownames contain the identifiers to track individual samples.

Where is the data.frame coming from? Are you reading it from a flat file (csv, tsv, etc) from disk? If you are using read.csv() function, it has the row.names argument, which can be set to 1 if your first column has row names.

data <- read.csv("/path/to/file.csv", row.names = 1)

您从未告诉过我们您对该数据框的处理方式,但是一种快速的解决方案是仅将第一行的一部分作为子集,然后在计算中使用该结果,即使用

df[2:nrow(df), ]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM