我有一个包含如下数据的dat文件:
<Avg. Price>$103
<URL>http://www.tripadvisor.com/ShowUserReviews-g60878-d100506-r21086254-
<Author>expressoparking
等
这是我用
标识每一行的脚本<Author>
标记,删除该标记,最后将该行的其余部分放入数据框中的单个列中。
y <- read.delim("hotel_100506.dat")
author <- grep("<Author>*", y$v1)
data_author <- y[author,]
author2 <- gsub("<Author>", "", author)
dataPractice <- data.frame(data_author)
我知道我的data_author变量具有正确的数据,但data.frame方法没有带来任何结果。这是怎么回事?
+++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++ ========================= ===============================================
Okey doke - 这是将作者标记行的信息放在数据框中的解决方案:
x <- read.delim("hotel_100505.dat", header = F)
Author <- grep("<Author>", x$V1)
data_Author <- x[Author,]
data_Author2 <- gsub("<Author>","",data_Author)
data <- data.frame(data_Author2)
答案 0 :(得分:0)
OP offers this as the solution, in a comment above:
x <- read.delim("hotel_100505.dat", header = F)
Author <- grep("<Author>", x$V1)
data_Author <- x[Author,]
data_Author2 <- gsub("<Author>","",data_Author)
data <- data.frame(data_Author2)