将txt文件读入R中的数据帧(reading txt file into data frame in R)
我有以下格式的文本文件:
"C1","name1","type1": 2 "C1","name2","type4": 6 "C2","name1","type2": 1 "C1","name3","type1": 10
我试过了:
db<- read.table("myfile.txt")
但这个文件存储为两列,并将值存储为“name1”,我也试过:
db<- read.csv("myfile.txt", header= FALSE)
但是这将最后两列存储为一列:
C1 name1 type1:2 C1 name2 type4:6 C2 name1 type2:1 C1 name3 type1:10
如何将最后两列存储为两个单独的列
C1 name1 type1 2 C1 name2 type4 6 C2 name1 type2 1 C1 name3 type1 10
谢谢
I have a text file in the following format:
"C1","name1","type1": 2 "C1","name2","type4": 6 "C2","name1","type2": 1 "C1","name3","type1": 10
I tried:
db<- read.table("myfile.txt")
but this stores the file as two column and store the values as "name1", I also tried :
db<- read.csv("myfile.txt", header= FALSE)
but this stores the last two columns as one column:
C1 name1 type1:2 C1 name2 type4:6 C2 name1 type2:1 C1 name3 type1:10
How can store the last two columns as two separate columns
C1 name1 type1 2 C1 name2 type4 6 C2 name1 type2 1 C1 name3 type1 10
thanks
原文:https://stackoverflow.com/questions/47595260
最满意答案
据我所知,没有直接的方法来确定是否可以嵌入字体。 我做了一个快速搜索,除了使用Erik在评论中提到的异常catch方法之外,我认为不可能。
// 1) have a list of all fonts ArrayList allAvailableFonts; // 2) second list of fonts that that can be embedded ArrayList embedableFonts; //Iterate through every available font in allAvailableFonts for( .... allAvailableFonts ..... ) { boolean isFontEmbeddable = true; try { // try to embed the font } catch( DocumentException de) { //this font cannot be embedded isEmbeddable = false; } if( isEmbeddable ) { // add to list of embeddable fonts embedableFonts.add ( font ); } }
您可以真正去硬核并执行对Windows Apis的本机调用以获得相同的结果,但我认为这对于一个简单的任务来说太多了。
做了一些研究,发现Java如何抛出这个异常
可以在此处找到生成上述异常的代码。 http://kickjava.com/src/com/lowagie/text/pdf/TrueTypeFont.java.htm行号367,368
if (!justNames && embedded && os_2.fsType == 2) throw new DocumentException(fileName + style + " cannot be embedded due to licensing restrictions.");
需要注意的有趣部分是条件
os_2.fsType == 2
os_2是
WindowsMetrics
一个实例,请参见第174行http://kickjava.com/src/com/lowagie/text/pdf/TrueTypeFont.java.htm在Google中搜索WindowsMetrics,这就是我所获得的。
这解释了参数fsType保存了是否可以嵌入字体的信息。 http://www.microsoft.com/typography/otspec/os2ver3.htm#fst
在itext中使用的java等价的WindowsMetrics http://www.docjar.org/docs/api/com/lowagie/text/pdf/TrueTypeFont.WindowsMetrics.html
As far as I can tell there is no direct way to identify whether a font can be embedded. I did a quick search and I don't think it is possible other than using the exception catch method as mentioned by Erik in the comments.
// 1) have a list of all fonts ArrayList allAvailableFonts; // 2) second list of fonts that that can be embedded ArrayList embedableFonts; //Iterate through every available font in allAvailableFonts for( .... allAvailableFonts ..... ) { boolean isFontEmbeddable = true; try { // try to embed the font } catch( DocumentException de) { //this font cannot be embedded isEmbeddable = false; } if( isEmbeddable ) { // add to list of embeddable fonts embedableFonts.add ( font ); } }
You can probably go really hardcore and execute native calls to Windows Apis to get the same result, but I think its too much work for a simple task as this.
Did some research and found out how this exception is thrown by Java
The code which generates the above exception can be found here. http://kickjava.com/src/com/lowagie/text/pdf/TrueTypeFont.java.htm Line number 367,368
if (!justNames && embedded && os_2.fsType == 2) throw new DocumentException(fileName + style + " cannot be embedded due to licensing restrictions.");
The interesting part to note is the condition
os_2.fsType == 2
os_2 is an instance of
WindowsMetrics
see line 174 here http://kickjava.com/src/com/lowagie/text/pdf/TrueTypeFont.java.htmA search for WindowsMetrics in Google and this was what I got.
This explains that the parameter fsType holds information whether font can be embedded. http://www.microsoft.com/typography/otspec/os2ver3.htm#fst
The java equivalent of WindowsMetrics as used in itext http://www.docjar.org/docs/api/com/lowagie/text/pdf/TrueTypeFont.WindowsMetrics.html
相关问答
更多-
据我所知,您无法检查单个符号,但您可以检查编码。 As far as I know, you can't check individual symbols, but you can check the encoding.
-
检查字体是否嵌入?(Check if font is embedded?)[2023-06-23]
您可以使用Font.enumerateFonts ,它将返回可用嵌入字体array 。 您可以使用它来创建如下所示的函数: private function hasEmbeddedFont(fontName:String):Boolean { var fonts:Array = Font.enumerateFonts(); for each(var font:Font in fonts) { if (font.fontName == fontName) ... -
根据您的澄清,听起来您在问一个关于解析XML的问题。 这是另一种选择:获取JSON,并解析它。 你可以提出类似的请求 http://gdata.youtube.com/feeds/api/videos/tYMYv1zsAxE?v=2&alt=jsonc&prettyprint=true 然后查看JSON响应中的data-> accessControl-> embed元素。 或者,您知道,只需解析和访问YouTube API XML就像您从任何其他来源解析XML一样。 YouTube API XML没有什么神 ...
-
您可以使用javascript尝试: http : //www.kirupa.com/html5/detect_whether_font_is_installed.htm 码: // // Call this function and pass in the name of the font you want to check for availability. // function doesFontExist(fontName) { // creating our in-memory Canva ...
-
如何检查父元素是div或font并返回fontsize?(How to check parent element is div or font and return fontsize?)[2022-03-07]
您可以使用window.getComputedStyle 。 在应用活动样式表并解析这些值可能包含的任何基本计算之后,此方法提供元素的所有CSS属性的值。 因此,对于font-size您可以执行以下操作: window.getComputedStyle(element, pseudo-element or null).getPropertyValue('font-size'); function changeFont() { var font = GetFont().split('px')[0]; ... -
如何检查Font Awesome是否在使用javascript的网页中加载?(How to check if Font Awesome is loaded in web page with javascript?)[2022-08-13]
我认为这是检查font-awesome的最好方法,但我不确定它是否比较慢,然后再加载它即使它在那里。 function css(element, property) { return window.getComputedStyle(element, null).getPropertyValue(property); } window.onload = function () { var span = document.createElement('span'); span.className ... -
你有没有看过Google Fonts API,特别是“针对事件”部分 ? Have you looked at the Google Fonts API, particularly the section 'Acting on events'?
-
好的,所以我最终终于想出了如何正确地做到这一点! 要获取此信息,请使用API密钥和视频ID向YouTube Data API v3发出HTTP GET请求: https://www.googleapis.com/youtube/v3/videos?id=
-
据我所知,没有直接的方法来确定是否可以嵌入字体。 我做了一个快速搜索,除了使用Erik在评论中提到的异常catch方法之外,我认为不可能。 // 1) have a list of all fonts ArrayList allAvailableFonts; // 2) second list of fonts that that can be embedded ArrayList embedableFonts; //Iterate through every available font in al ...
-
有一个可嵌入的JBoss ejb3,Embeddable EJB3用于什么?(there are a embeddable ejb3 of JBoss, what the Embeddable EJB3 for?)[2022-07-22]
来自JBoss网站:Embeddable EJB 3.0可以在独立应用程序,junit测试,Tomcat甚至其他非jboss应用程序服务器的应用程序服务器之外运行。 From JBoss website: Embeddable EJB 3.0 can be run outside of the application server in standalone applications, junit tests, Tomcat, or even other non-jboss application serv ...