2016-12-02 112 views
0

我有这样R:如何引用一个数据帧的值在for循环中的R

Tweets 
1                     Thank you @DiscoveryIN. very inspirational to watch #Jaiho 
2    @DiscoveryIN @arrahman Your music has always been inspirational sir. Your life is doubly inspirational. Thanks for sharing. 
3      @oyorooms @OYO4U Thanks for listening to my concerns. Hope things will turn better in future. Booking id - DYER2375 
4 @oyorooms Next time when i will book thru @makemytrip. Or worst, I will sleep in my car than booking thru @oyorooms . Booking id DYER2375 

我想读R中的上述数据帧内部的for循环数据frmae

for(i in 1:nrow(tweets)){ 
    TEXT = URLencode('tweets[i,]') >>>>>>>>> 
    print(TEXT) 
} 

我想引用for循环内的第一条记录的值。但是,打印此结果会得到如下结果而不是实际值。

> TEXT 
[1] "tweets[i,]" 

如何获得实际值?

应该是这样的

> print(TEXT) 
[1] "@DiscoveryIN%20Thank%20you%[email protected]%20very%20inspirational%20to%20watch%20#Jaiho" 

如何实现这一目标?

+0

'进行urlencode(微博[我,1])'? – nrussell

+0

@nrussell - 这会导致错误 - strsplit错误(URL,“”):非字符参数 –

回答

2

您需要将值打印为URLencode的字符串。

你可以使用sprintf

URLencode(sprintf("%s",tweets[i,1])) 

或者你可以使用paste

URLencode(paste(tweets[i,1])) 
+0

谢谢你这个工作 –