Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将列表转换为R中dataframe列中的字符串_R_String - Fatal编程技术网

将列表转换为R中dataframe列中的字符串

将列表转换为R中dataframe列中的字符串,r,string,R,String,我有一个数据框,其中一个列conatins列出数据,希望将其转换为字符串,当我将一个数据框子集时,我得到的值低于-->df[2,4] [1] "marianna g: hello dr ydeen how can i help you"

我有一个数据框,其中一个列conatins列出数据,希望将其转换为字符串,当我将一个数据框子集时,我得到的值低于-->
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"
我想将其转换为字符串,所以当我执行df[2,4]时,我应该得到以下输出:

"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"

看起来df[2,4]是一个向量。要使其成为字符串,只需使用
粘贴
-函数。 作为参数,您需要指定
collapse=“
将所有内容粘贴在一起,并在以下内容之间留有空格:

paste(df[2,4],collapse=" ")
如果你想把它们用逗号分隔成一个字符串,只需使用

paste(df[2,4],collapse=", ")

您应该能够将该列传递给paste()函数,然后将其重新分配给该列:


df[2,4]这是更正确的答案。一个小问题-R中没有
string
数据类型。上述方法将长度为9的字符向量转换为长度为1的字符向量。我尝试了粘贴函数,但得到的是一个字符向量,我需要一个字符串,其次是如何将其应用于dataframe的完整列