我有一个看起来像这样的数据框
df=data.frame(ID=c(1,2,3),hashtag=c('c("#job", "#inclusion<U+0085>", "#driver", "#splitme")','c("#job", "#inclusion<U+0085>", "#driver")','c("#job", "#inclusion<U+0085>")'))
我首先进行一些清理工作,然后根据每个单元格中的主题标签数量将列hashtag
拆分为多个列。例如,第一列有4个主题标签,因此将分为四个不同的列#job
,#inclusion
,diversity
,splitme
我尝试了以下
#Clean up
#Remove inverted commas
df$hashtag <- gsub('"', '', df$hashtag)
#Remove brackets
df$hashtag <-gsub("c\\(|\\)", "", df$hashtag)
#Then Split columns
df_split=df%>% separate(hashtag, c("A", "B","C","D"),sep=', ',extra = "drop")
当我尝试使用以下代码行删除unicode时,没有任何反应。
#Remove unicode
df$hashtag <-gsub("\\<|\\>", "", df$hashtag)
关于什么是正确的解决方案的任何想法?
答案 0 :(得分:1)
您没有指定输出,但您可以按照
进行操作import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class ListRemoveFromListener extends Application {
boolean changing = false;
@Override
public void start(Stage primaryStage) throws Exception {
VBox vbox = new VBox();
Button buttonSuccess = new Button("remove success");
buttonSuccess.setOnAction(e -> {
removeSuccess();
});
Button buttonBreak = new Button("Remove breaks");
buttonBreak.setOnAction(e -> {
removeBreaks();
});
vbox.getChildren().addAll(buttonSuccess, buttonBreak);
Scene scene = new Scene(vbox);
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* If we try in listener to remove element just next to one that was
* initially removed, exception is thrown.
*/
private void removeBreaks() {
ObservableList<String> list = FXCollections.observableArrayList();
list.add("first");
list.add("second");
list.add("third");
list.add("fourth");
list.add("fifth");
list.add("sixth");
list.addListener(new ListChangeListener<String>() {
@Override
public void onChanged(Change<? extends String> c) {
list.remove("second");
}
});
list.remove("third");
}
/**
* If we try in listener to remove element that is not just next to initially
* removed element, element is removed and all works O.
*/
private void removeSuccess() {
ObservableList<String> list = FXCollections.observableArrayList();
list.add("first");
list.add("second");
list.add("third");
list.add("fourth");
list.add("fifth");
list.add("sixth");
list.addListener(new ListChangeListener<String>() {
@Override
public void onChanged(Change<? extends String> c) {
list.remove("fifth");
}
});
list.remove("third");
}
public static void main(String[] args) {
launch(args);
}
}