应用str_split的专栏中,我有以下DF名为I:在数据帧
structure(list(price = c(11772, 14790, 2990, 1499, 21980, 27999
), fuel = c("diesel", "petrol", "petrol", "diesel", "diesel",
"petrol"), gearbox = c("manual", "manual", "manual", "manual",
"automatic", "manual"), colour = c("white", "purple", "yellow",
"silver", "red", "rising blue metalli"), engine_size = c(1685,
1199, 998, 1753, 2179, 1984), mileage = c(18839, 7649, 45058,
126000, 31891, 100), year = c("2013 hyundai ix35", "2016 citroen citroen ds3 cabrio",
"2007 peugeot 107 hatchback", "2007 ford ford focus hatchback", "2012 jaguar xf saloon",
"2016 volkswagen scirocco coupe"), doors = c(5, 2, 3, 5, 4, 3
)), .Names = c("price", "fuel", "gearbox", "colour", "engine_size",
"mileage", "year", "doors"), row.names = c(NA, 6L), class = "data.frame")
一些“年”列中的字被复制。我想删除它们。作为第一步,我想用单独的单词分隔此列中的字符串。 我能做到这一点单独的字符串,但是当我尝试将其应用到整个数据帧它给出了一个错误
unlist(str_split("2013 hyunday ix35", "[[:blank:]]"))
[1]“2013”“hyunday”,“ix35的”
for(k in 1:nrow(i))
+ i[k,7]<-unlist(str_split(i[k, 7], "[[:blank:]]"))
错误[<-.data.frame
(*tmp*
,K,7,值= C( “2013”, “现代”,: 更换已3行,数据具有1
它工作正常。我试图使用sapply,但不知道如何将两个功能(粘贴和独特)结合在一起。 – Vasile