Home > front end >  Cant change name of colnames in text file using R
Cant change name of colnames in text file using R

Time:11-06

my text file :

jack,28,25.2
smith,23,10.5
lena,49,11
leo,29,21.9
sara,38,44
ibra,23,11.5
Ayan,29,45
sample <- read.table("sample.txt", sep = "|",  header=F)
colnames(sample) <- c("name","age","income")

i try to change name of col but i have error:

'names' attribute [3] must be the same length as the vector [1]

CodePudding user response:

Welcome to Stackoverflow, Abdullah Alotaibi!

As mentioned in the comments you should use read.csv("sample.txt", header=FALSE) or read.csv("sample.txt",sep=",", header=FALSE) .

Because of the use of , as seperator in your textfile.

  •  Tags:  
  • r
  • Related