• Register
0 votes
658 views

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

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

Solution:

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
                               Stage_Sex
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 281 views
281 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 452 views
452 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 815 views
815 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.3K views
1.3K 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.3K views
1.3K 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