• 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 384 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 749 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
2 answers 1.2K views
Problem : I am looking for the function with the parameters such as data name as (mydata), factor as (myfactor) and variable names such as (myvar) to dynamically generate the histograms as I have to use them in lattice. I tried to do as mentioned above but error appears ... of type 'character'. I think the program doesn't know where to look for this myf` string. How should I fix this issue?
asked Dec 23, 2019 alecxe 7.5k points
0 votes
1 answer 1.8K views
Problem : I have been facing below error message and traceback: Error in FUN(X[[i]], ...) : only defined on the data frame with all numeric variables 5 stop("only defined on the data frame with all numeric variables") 4 FUN(X[[i]], ...) 3 lapply(args, ... .numeric(data[good,]) But now I get the different error message back as below : "Error: (list) object cannot be coerced to type 'double'"
asked Dec 16, 2019 alecxe 7.5k points
1 vote
1 answer 1.7K views
Problem : I am facing following error : formula(formula, data = data) : invalid model formula in ExtractVars I am using the below code: install.packages("rpart") library("rpart") # you must change the below from windows to work on your linux box: mydata <- read.csv(file="c ... file to commas. I guess it is unable to read the data correctly. I am very new to the R and also a very new programmer.
asked Dec 14, 2019 alecxe 7.5k points
0 votes
1 answer 714 views
Problem : I want to use the neural net for predictions. I am trying to create some X as follows : x <- cbind(seq(1, 50, 1), seq(51, 100, 1)) I am trying to create some Y as follows : y <- x[,1]*x[,2] Give them the names as follows colnames(x) ... =0.01) error in terms.formula(formula) : '.' in formula and no 'data' argument Does anybody have any idea regarding the error I am facing? Any solution?
asked Dec 11, 2019 alecxe 7.5k points
0 votes
2 answers 1.3K views
Problem : I am facing below error and I am unable to understand the meaning of the error. All my variable names are correct and there are no typing errors. Does anybody faced this issue before any solution on it? My erroneous code : datNewagg <- aggregate (dataNew, by = ... mean) It gives following error : Error in aggregate.data.frame(datNew, by = list("x", "y", : arguments must have same length
asked Dec 6, 2019 alecxe 7.5k points
0 votes
1 answer 215 views
Problem : I want to use the TraMineR's (version 1.8.4) seqdef-funciton to define the sequence object, however I always face the following error message which is completely senseless to me: Error in row.names<-.data.frame(*tmp*, value = value) : invalid 'row. ... tried running it after re-labeling the states without "-", but it does not affect the error. Does someone knows what causes this error?
asked Dec 6, 2019 alecxe 7.5k points
0 votes
1 answer 1.3K views
Problem : When ever i use the predict glmnet function i get the below mentioned error error in cbind2(1, newx) %*% nbeta : not-yet-implemented method for <data.frame> %*% <dgcmatrix>
asked Nov 12, 2019 peterlaw 6.9k points
0 votes
1 answer 63 views
Problem : Getting following error related to r error in `row.names<-.data.frame`(`*tmp*`, value = value) : duplicate 'row.names' are not allowed
asked Nov 11, 2019 peterlaw 6.9k points