How to define a column class in R, dataframe
1
0
Entering edit mode
2.0 years ago
mthm ▴ 50

Hi,

I asked this question in other forums but couldn't get the answer for it, I hope somebody can help me here.

I have a data frame like this

scf0001    123    4567   -  4350
scf0001    4474   4878   +  376  *
scf0002    5375   10571  c  5006
scf0003    11370  16986  c  5536
scf0003    16256  17000  -  789  *

when I attempt to read it as a table in R, the error is line 2 did not have 5 elements, so it is not recognizing the star(), I tried to read it as string with `na.string="" but it didn't work, so I think I have to define it withcolclasses=. I tried something like thiscolClasses=[, c(6)="character"]to define the 6th column of the table but it doesn't work,Error: unexpected '['`

The only answer I received was to use fill = TRUE but what it did was to create a new row for the stars rather than defining them as the last column

scf0001    123    4567   -  4350
scf0001    4474   4878   +  376
*          NA      NA    NA   NA
scf0002    5375   10571  c  5006

any idea how to work around this?

colclasses R dataframe • 459 views
ADD COMMENT
2
Entering edit mode
2.0 years ago
> read.table("test.txt", fill = T, row.names = NULL, header = F)

       V1    V2    V3 V4   V5 V6
1 scf0001   123  4567  - 4350   
2 scf0001  4474  4878  +  376  *
3 scf0002  5375 10571  c 5006   
4 scf0003 11370 16986  c 5536   
5 scf0003 16256 17000  -  789  *
ADD COMMENT

Login before adding your answer.

Traffic: 2063 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6