Error when reading in a .txt file and splitting it into columns in R -


i read in .txt file r, , have done numerous times. @ moment however, not getting desired output.

i have .txt file contains data x want, , other data not, in front , after data x.

here printscreen of .txt file

enter image description here

i able read in txt file followed:

read.delim("c:/users/toxicologie/cobalt/wb1", header=true,skip=88, nrows=266) 

this gives me dataframe 266 obs of 1 variable. enter image description here

but want these 266 observations in 4 columns (id, species, endpoint, blm noec).

so tried following script:

read.delim("c:/users/toxicologie/cobalt/wb1", header=true,skip=88, nrows=266, sep = " ") 

but error

error in read.table(file = file, header = header, sep = sep, quote = quote,  : more columns column names 

using sep = "\t" gives same error.

and not sure how can fix this.

any appreciated!

try read.fwf , specify widths of each column. start reading @ aelososoma sp. row , add column names afterwards

something like:

df <-  read.fwf("c:/users/toxicologie/cobalt/wb1", header=true,skip=88, n=266,widths=c(2,35,15,15))  colnames(df) <- c("id", "species", "endpoint", "blm noec") 

provide txt file more complete answer.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -