Reputation: 115
I have a dataframe, where one of the column conatins list data, want to convert it to string, when I subset a dataframe I get below value--> df[2,4]
[1] "marianna g: hello dr ydeen how can i help you"
[2] "marianna g: yes you can view that in your secure hr page under benefits summary first youll have to enter the last four of your ssn on the right hand side youll be directed to your secure hr page and on the left hand side there will be a list of links select benefits summary"
[3] "marianna g: you can also view it on each pay stub biweekly"
[4] "marianna g: youll have to select the quotprintviewquot option on the paycheck and the accruals are listed under your earnings"
[5] "marianna g: great yes thats correct"
[6] "marianna g: its your accruals as of the last pay period"
[7] "marianna g: so currently its accurate up until"
[8] "marianna g: my pleasure anything else i can help you with"
[9] "marianna g: have a great day"
I want to convert it to string so when I do df[2,4], i should get below output:
"marianna g: hello dr ydeen how can i help you, marianna g: yes you can view that in your secure hr page under benefits summary first youll have to enter the last four of your ssn on the right hand side youll be directed to your secure hr page and on the left hand side there will be a list of links select benefits summary, marianna g: you can also view it on each pay stub biweekly, marianna g: youll have to select the quotprintviewquot option on the paycheck and the accruals are listed under your earnings, marianna g: great yes thats correct, marianna g: its your accruals as of the last pay period, marianna g: so currently its accurate up until, marianna g: my pleasure anything else i can help you with, marianna g: have a great day"
Upvotes: 0
Views: 919
Reputation: 109
You should be able to pass the column to the paste() function and then reassign it to that column:
df[2,4] <- paste(df[2,4])
Upvotes: 0
Reputation: 1810
It seems like df[2,4] is a vector. To make it a string, just use the paste
-function.
As argument, you need to specify collapse=" "
to paste everything together with a space between:
paste(df[2,4],collapse=" ")
If you want to have them comma-seperated in a string, just use
paste(df[2,4],collapse=", ")
Upvotes: 2