0

What is the right way to parse this into a two column dataframe? If I split based on spaces it splits too many times, but if I don't split at all everything stays in one column. Would I have to download it with one line, then split on the first space via regex, or is there a better method?

item.ids<-read.csv("http://eve-files.com/chribba/typeid.txt",sep =' ',header=F)
View(item.ids)
0

1 Answer 1

2

Read it in as fixed-width. Using readr (translate to base if you like counting characters):

library(readr)

df <- read_fwf('http://eve-files.com/chribba/typeid.txt', 
               fwf_empty('http://eve-files.com/chribba/typeid.txt', 
                         skip = 2, 
                         col_names = c('typeID', 'typeName')), 
               skip = 2)

df

## # A tibble: 22,385 × 2
##    typeID           typeName
##     <int>              <chr>
## 1       0            #System
## 2       2        Corporation
## 3       3             Region
## 4       4      Constellation
## 5       5       Solar System
## 6       6    Sun G5 (Yellow)
## 7       7    Sun K7 (Orange)
## 8       8 Sun K5 (Red Giant)
## 9       9      Sun B0 (Blue)
## 10     10     Sun F0 (White)
## # ... with 22,375 more rows
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.