• Register
0 votes

Problem :

How to solve the below error, I will first show an example of the data file.

My Data file:

col1  col2    col3

1     2       3

1     2       3

5     6       7


My R code:

read.table("mydemo.txt", header = TRUE, sep = "\t", row.names = "a")

My Output:

> Error in data[[rowvar]] : attempt to select less than one element

In addition: Warning message:

In read.table(file = file, header = header, sep = sep, quote = quote,  :

incomplete final line found by readTableHeader on '../mydemo.txt'


7 5 2
3,870 points

Please log in or register to answer this question.

2 Answers

0 votes

Solution :

The row.names is:

The vector of row names. This can be a vector giving a actual row names, or a single number giving a column of the table which contains a row names, or character string giving a name of the table column containing a row names.

If there is the header and a first row contains one fewer field than a number of columns, a first column in a input is used for a row names. Otherwise if row.names is missing, a rows are numbered.

Using a row.names = NULL forces row numbering. Missing or NULL row.names generate a row names that are considered to be the ‘automatic’ (and not preserved by as.matrix).

So you can provide either a name of a column (like "col1" in your example), or the vector of names for each row.

9 7 4
38,600 points
0 votes


The problem is reasoned by row.names = "a". Data set should have diverse row names. In case you attempt to name all rows "a", you obtain the error. In case you have a vector which comprises the row names you need to use, you can do this.

> a <- c("A", "B", "C")
> read.table("demo.txt", header = TRUE, row.names = a)
  clo1 clo2 clo3
A    1    2    3
B    1    2    3
C    5    6    7

You require to do:

colData <- read.table(file.choose(),header=TRUE, row.names = "gene_id", sep=",")

I have included sep=","

as.matrix(read.csv("counts.test", row.names = "gene_id"))
            Alsk_10.5_B150f_Gam_1 Alsk_10.5_B150f_Gam_2 Alsk_10.5_B150f_Gam_3
MSTRG.20438                160107                112757                    NA
MSTRG.19848                  1401                  1286                  1533

read.table("colData.test", header=TRUE, row.names = "gene_id", sep=",")
                            Stage    Sex    Isolate Population
Alsk_10.5_B150f_Gam_1 Gametophore Female Alsk_B150f     Alaska
Alsk_10.5_B150f_Gam_2 Gametophore Female Alsk_B150f     Alaska
Alsk_10.5_B150f_Gam_1 Gametophore_Female
Alsk_10.5_B150f_Gam_2 Gametophore_Female
10 6 4
31,120 points

Related questions

0 votes
1 answer 36 views
Problem: attempt to select less than one element in integeroneindex.
asked Feb 18 charles mathews 5.5k points
0 votes
1 answer 8 views
Problem: The error looks like this decompose(samplets) Error in decompose(samplets) : time series has no or less than 2 periods
asked Mar 18 ummesalma 25.2k points
0 votes
1 answer 3 views
Problem: Please help me &hellip; how can I solve it? error attempt to apply non-function
asked Mar 22 Ifra 24.4k points
0 votes
1 answer 500 views
Problem : I want to select some columns from my data frame by the use of below code: library(dplyr) dv %>% select(LGA) select(dv, LGA) Both of them are failing with below error : Unable to find an inherited method for function select' for signature ... (leaflet) library(mapview) library(RColorBrewer) library(scales) I' am very new to R, so need guidance in resolving the problems like this?
asked Dec 7, 2019 alecxe 7.5k points
0 votes
1 answer 2 views
Question: What is the correct way to change the levels of a factor column in a data.table (note: not data frame) library(data.table) mydt <- data.table(id=1:6, value=as.factor(c("A", "A", "B", "B", "B", "C")), key="id") mydt[, levels(value)] [1] "A" "B" "C" I am looking for something like: mydt[, levels(value) ... 1: 1 A 1: 1 X 2: 2 A 2: 2 X 3: 3 B 3: 3 Y 4: 4 B 4: 4 Y 5: 5 B 5: 5 Y 6: 6 C 6: 6 Z
asked 1 day ago Atik03 10.1k points
0 votes
1 answer 4 views
Problem: a one-way data table summarizes.
asked Mar 23 charles mathews 5.5k points
0 votes
1 answer 6 views
Problem: I'm trying to run the following code in R, but I'm getting an error: R attempt to apply non-function I'm not sure what part of the formula is incorrect. Any help would be greatly appreciated.
asked Mar 30 ummesalma 25.2k points
0 votes
1 answer 8 views
Problem: HELP! I need help understanding this problem? attempt to make a table with >= 2^31 elements
asked Mar 26 Rohit kr 16.2k points
0 votes
1 answer 1.1K views
Problem : I am trying to merge data in R but facing following error error in fix.by(by.x, x) : 'by' must specify one or more columns as numbers, names or logical
asked Nov 15, 2019 peterlaw 6.9k points
0 votes
1 answer 18 views
Problem: How should I fix this issue: Error in eval(predvars, data, env) : invalid 'envir' argument of type 'character'.
asked Mar 14 Wafa Abu Yousef 6.1k points