Reputation: 21
I have a long column with about 5000 rows and each row has 6 digits. I would like to remove the first digit of the first 150 rows. How do I do that?
I tried this function:
gsub("^[0-9]","", f1992$cleaned1992)
f1992
is the dataframe and cleaned1992
is the column that I am working with. The problem is the code removes the first digit for all the 5000 rows.
Upvotes: 2
Views: 96
Reputation: 389175
With sub
you can do
f1992$cleaned1992[1:150] <- sub(".", "", f1992$cleaned1992[1:150])
Or using substring
f1992$cleaned1992[1:150] <- substring(f1992$cleaned1992[1:150], 2)
Upvotes: 0
Reputation: 3335
Just index to the first 150 rows
gsub("^[0-9]","", f1992$cleaned1992[1:150])
Upvotes: 1