I am new to r and am using the read.table command to import a text file. My column names are PatID, AgePat, SexPat and WeightPat. I want to change these to simply PatID (no change), Age, Sex and Weight. How do I do this? Thanks,
read.table
has a col.names
argument
read.table("/path/to/file", header=TRUE, col.names=c("PatID", "Age", "Sex", "Weight"))
Here are two ways to do what you want:
colnames(data) [2:4] <- c("Age","Sex","Income")
or
colnames(x)[2:4] <- sub("Pat","",colnames(x)[2:4])
If you're new to R, I would recommend the ebook "R Fundamentals & Graphics" which will give you a solid grasp of R basics. Better than fumbling around and wasting your time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With