data.frame Using Vector of Names - r

Can I use a vector of variable names to make a data frame?
have=c("aaa","bbb","ccc","ddd","eee","fff","ggg","hhh","iii","jjj")
for(i in 1:10){assign(have[i],rnorm(10))}
want=data.frame(aaa,bbb,ccc,ddd,eee,fff,ggg,hhh,iii,jjj)
I wonder if I can alter the last aaa,bbb,ccc,ddd,eee,fff,ggg,hhh,iii,jjj somehow using have.

Assume that all variables in have are stored in the Global environment. Then you can also try this:
want <- as.data.frame(mget(have))

You could do
have=c("aaa","bbb","ccc","ddd","eee","fff","ggg","hhh","iii","jjj")
for(i in 1:10){assign(have[i],rnorm(10))}
want <- data.frame(sapply(have, get))
want
#> aaa bbb ccc ddd eee fff
#> 1 2.2111971 0.58169621 0.7558816 -1.6408627 0.7975625 0.09160389
#> 2 -0.7847731 1.60423888 0.3819555 -1.2061538 0.7545381 -0.64964125
#> 3 -1.2757056 0.57714761 0.4700359 -1.1041282 -0.3816839 0.40549014
#> 4 -0.0360762 -1.29007252 -0.7820075 -0.5319163 -0.2999686 0.51213744
#> 5 0.1763021 0.82259576 -0.4409983 1.4809103 -0.3658530 -0.16434920
#> 6 1.3196823 -0.18163744 1.5261259 1.3087872 -1.0644242 -1.31891628
#> 7 0.4076277 -0.89769591 -0.7778384 -0.3837985 -1.8659484 -1.53683062
#> 8 1.1872413 -0.06917426 0.3875081 0.4146543 -0.7035016 -0.63534985
#> 9 0.9037385 0.10581530 0.6210197 2.4435195 -1.2323838 0.84316865
#> 10 -0.8933586 1.47698413 0.4561502 1.0824430 2.2895535 0.05699095
#> ggg hhh iii jjj
#> 1 -0.4915989 -0.02034347 -1.6870239 -1.08651315
#> 2 1.7595238 0.47375431 0.5408044 0.65031636
#> 3 -2.0502394 0.85440730 -0.4114844 -0.17392623
#> 4 -1.1268393 0.68303043 1.1722424 -0.90590156
#> 5 -1.3235682 0.59603361 -0.8958801 -0.94192724
#> 6 -0.3669457 -0.27870024 1.8228263 0.01478657
#> 7 0.6525810 -0.00354290 0.3757264 0.34386963
#> 8 -0.3378531 -0.45219282 -0.8959065 -0.43244283
#> 9 0.3931531 0.61264470 0.6359348 0.02984539
#> 10 -0.5256779 0.79624735 -2.2912426 -1.06220090
Created on 2020-10-03 by the reprex package (v0.3.0)

Related

apply gsub over a certain column in a list of data frames

I have a list of data frames -results1- where the data frames look like this (but with more rows)
names coefficients
1 ..a15.pdf 1.27679608
2 ..a17.pdf 1.05090176
I want to remove the dots before the variables in column 'names', i.e. change "..a15.pdf" to "a15.pdf".
I tried, with no success, different variations of
results1<-lapply(results1, function(x) {gsub("^.{0,2}", "", lapply(x, "[", "names"));x})
First two data frames from the list:
dput(results1[c(1,2)])
list(structure(list(names = c("..a15.pdf", "..a17.pdf", "..a18.pdf",
"..a21.pdf", "..a2TTT.pdf", "..a5.pdf", "..B11.pdf", "..B12.pdf",
"..B13.pdf", "..B22.pdf", "..B24.pdf", "..B4.pdf", "..B7.pdf",
"..B8.pdf", "..cw10-1.pdf", "..cw15-1TTT.pdf", "..cw17-1.pdf",
"..cw18.pdf", "..cw3.pdf", "..cw4.pdf", "..cw7_1TTT.pdf", "..cw13-1.pdf"
), coefficients = c(1.27679607834331, 1.05090175857491, 1.51820192474905,
2.30296037386815, 1.48568731934637, 0.493713103224402, 1.02705905465749,
0.999747360884078, 2.40828101927852, 0.695152132033603, 2.1436001615064,
2.25444037842867, 0.909773940025014, 1.14837173756827, -1.36323271003293,
0.341428535787024, -0.786878348480425, 0.793720472787986, -1.57831038567642,
0.277733503122777, -0.0364645818969112, -18.336668416705)), class = "data.frame", row.names = c(NA,
-22L)), structure(list(names = c("..a15.pdf", "..a17.pdf", "..a18.pdf",
"..a21.pdf", "..a2TTT.pdf", "..a5.pdf", "..B11.pdf", "..B12.pdf",
"..B13.pdf", "..B22.pdf", "..B24.pdf", "..B4.pdf", "..B7.pdf",
"..B8.pdf", "..cw10-1.pdf", "..cw15-1TTT.pdf", "..cw17-1.pdf",
"..cw18.pdf", "..cw3.pdf", "..cw4.pdf", "..cw7_1TTT.pdf", "..cw13-1.pdf"
), coefficients = c(2.096687569578, 2.19826038300833, 1.91814204277357,
0.801448541154512, 2.16169560949165, 1.48585130705963, 0.95126061691997,
1.93116618236938, 1.92555316191766, 1.00560861920225, 2.91129684208931,
2.75687804718002, 1.31164431967781, 2.22449059765255, -1.22629519335285,
1.31168579553008, -17.5786422399896, 1.25323523754693, -0.754445550651364,
0.555577381430987, 0.577850999404076, -34.2662973287062)), class = "data.frame", row.names = c(NA,
-22L)))
You have to escape . in gsub by using \\ two backslashes. This will replace all (any number of) dots preceeding the actual name.
results <- list(structure(list(names = c("..a15.pdf", "..a17.pdf", "..a18.pdf",
"..a21.pdf", "..a2TTT.pdf", "..a5.pdf", "..B11.pdf", "..B12.pdf",
"..B13.pdf", "..B22.pdf", "..B24.pdf", "..B4.pdf", "..B7.pdf",
"..B8.pdf", "..cw10-1.pdf", "..cw15-1TTT.pdf", "..cw17-1.pdf",
"..cw18.pdf", "..cw3.pdf", "..cw4.pdf", "..cw7_1TTT.pdf", "..cw13-1.pdf"
), coefficients = c(1.27679607834331, 1.05090175857491, 1.51820192474905,
2.30296037386815, 1.48568731934637, 0.493713103224402, 1.02705905465749,
0.999747360884078, 2.40828101927852, 0.695152132033603, 2.1436001615064,
2.25444037842867, 0.909773940025014, 1.14837173756827, -1.36323271003293,
0.341428535787024, -0.786878348480425, 0.793720472787986, -1.57831038567642,
0.277733503122777, -0.0364645818969112, -18.336668416705)), class = "data.frame", row.names = c(NA,
-22L)), structure(list(names = c("..a15.pdf", "..a17.pdf", "..a18.pdf",
"..a21.pdf", "..a2TTT.pdf", "..a5.pdf", "..B11.pdf", "..B12.pdf",
"..B13.pdf", "..B22.pdf", "..B24.pdf", "..B4.pdf", "..B7.pdf",
"..B8.pdf", "..cw10-1.pdf", "..cw15-1TTT.pdf", "..cw17-1.pdf",
"..cw18.pdf", "..cw3.pdf", "..cw4.pdf", "..cw7_1TTT.pdf", "..cw13-1.pdf"
), coefficients = c(2.096687569578, 2.19826038300833, 1.91814204277357,
0.801448541154512, 2.16169560949165, 1.48585130705963, 0.95126061691997,
1.93116618236938, 1.92555316191766, 1.00560861920225, 2.91129684208931,
2.75687804718002, 1.31164431967781, 2.22449059765255, -1.22629519335285,
1.31168579553008, -17.5786422399896, 1.25323523754693, -0.754445550651364,
0.555577381430987, 0.577850999404076, -34.2662973287062)), class = "data.frame", row.names = c(NA,
-22L)))
library(tidyverse)
results %>% map(~ .x %>% mutate(names = gsub('^\\.*(.*)$', '\\1', names)))
#> [[1]]
#> names coefficients
#> 1 a15.pdf 1.27679608
#> 2 a17.pdf 1.05090176
#> 3 a18.pdf 1.51820192
#> 4 a21.pdf 2.30296037
#> 5 a2TTT.pdf 1.48568732
#> 6 a5.pdf 0.49371310
#> 7 B11.pdf 1.02705905
#> 8 B12.pdf 0.99974736
#> 9 B13.pdf 2.40828102
#> 10 B22.pdf 0.69515213
#> 11 B24.pdf 2.14360016
#> 12 B4.pdf 2.25444038
#> 13 B7.pdf 0.90977394
#> 14 B8.pdf 1.14837174
#> 15 cw10-1.pdf -1.36323271
#> 16 cw15-1TTT.pdf 0.34142854
#> 17 cw17-1.pdf -0.78687835
#> 18 cw18.pdf 0.79372047
#> 19 cw3.pdf -1.57831039
#> 20 cw4.pdf 0.27773350
#> 21 cw7_1TTT.pdf -0.03646458
#> 22 cw13-1.pdf -18.33666842
#>
#> [[2]]
#> names coefficients
#> 1 a15.pdf 2.0966876
#> 2 a17.pdf 2.1982604
#> 3 a18.pdf 1.9181420
#> 4 a21.pdf 0.8014485
#> 5 a2TTT.pdf 2.1616956
#> 6 a5.pdf 1.4858513
#> 7 B11.pdf 0.9512606
#> 8 B12.pdf 1.9311662
#> 9 B13.pdf 1.9255532
#> 10 B22.pdf 1.0056086
#> 11 B24.pdf 2.9112968
#> 12 B4.pdf 2.7568780
#> 13 B7.pdf 1.3116443
#> 14 B8.pdf 2.2244906
#> 15 cw10-1.pdf -1.2262952
#> 16 cw15-1TTT.pdf 1.3116858
#> 17 cw17-1.pdf -17.5786422
#> 18 cw18.pdf 1.2532352
#> 19 cw3.pdf -0.7544456
#> 20 cw4.pdf 0.5555774
#> 21 cw7_1TTT.pdf 0.5778510
#> 22 cw13-1.pdf -34.2662973
Created on 2021-06-04 by the reprex package (v2.0.0)
Solution with tidyverse
library(purrr)
library(dplyr)
library(stringr)
map(results1, ~.x[]%>%
mutate(names = str_replace_all(names,"\\.\\.", "")))
[[1]]
names coefficients
1 a15.pdf 1.27679608
2 a17.pdf 1.05090176
3 a18.pdf 1.51820192
4 a21.pdf 2.30296037
5 a2TTT.pdf 1.48568732
6 a5.pdf 0.49371310
7 B11.pdf 1.02705905
8 B12.pdf 0.99974736
9 B13.pdf 2.40828102
10 B22.pdf 0.69515213
This worked for me:
lapply(your_list, function(df) dplyr::mutate(df, column = gsub(x = column, pattern = "pattern", replacement = "replacement")))
your_list- the list containing dataframes
column- the variable inside the dataframes where you want to do the gsub
In this way I found that the code did not change the class of the other variables in my dataframes

R-Mosaic: Is there a mean.n function?

is there a mean.n function (just as in SPSS) in mosaic in R?
I have 3 columns of data (including "NA") and I want a new column to have the means of the 3 data points for each row. How do I do that?
rowMeans might be just what you are looking for. It will return the row-wise mean, make sure to select/subset the right columns.
Here is an example
# Load packages
library(dplyr)
# Example data
ex_data = data.frame(A = rnorm(10), B = rnorm(10)*2, C = rnorm(10)*5)
ex_data
#> A B C
#> 1 0.2838024 -1.8784902 -2.7519131
#> 2 -0.4090575 1.6457548 6.1643390
#> 3 0.2061454 0.2103105 7.2798434
#> 4 -1.5246471 -0.6071042 -7.2411695
#> 5 -1.0461921 -2.6290405 -1.3840000
#> 6 -1.4802151 1.9323571 5.8539328
#> 7 0.1827485 0.1608848 -0.5157152
#> 8 -0.3006229 2.8650122 -1.4393171
#> 9 2.2981543 -0.2790727 2.6193970
#> 10 1.0495951 -0.9061784 -4.4013859
# Use rowMeans
ex_data$abc_means = rowMeans(x = ex_data[1:3])
ex_data
#> A B C abc_means
#> 1 0.2838024 -1.8784902 -2.7519131 -1.44886698
#> 2 -0.4090575 1.6457548 6.1643390 2.46701208
#> 3 0.2061454 0.2103105 7.2798434 2.56543308
#> 4 -1.5246471 -0.6071042 -7.2411695 -3.12430691
#> 5 -1.0461921 -2.6290405 -1.3840000 -1.68641084
#> 6 -1.4802151 1.9323571 5.8539328 2.10202491
#> 7 0.1827485 0.1608848 -0.5157152 -0.05736064
#> 8 -0.3006229 2.8650122 -1.4393171 0.37502404
#> 9 2.2981543 -0.2790727 2.6193970 1.54615953
#> 10 1.0495951 -0.9061784 -4.4013859 -1.41932305
You mentioned that you have NAs in your data, make sure to include na.rm = TRUE if appropriate.
Created on 2021-04-02 by the reprex package (v0.3.0)

How to create a 2 variable barplot using ggplot2 in r

I have a data frame and i want to plot a bar chart with two numerical values bars side by side namely Mean_dbh and Low_AGC for each given location (SU)
How do i plot this using ggplot2
SU Mean_dbh Low_AGC
1 1 16.98921 17.696251
2 2 13.48199 8.108352
3 3 15.97746 14.584501
4 4 12.14046 28.910114
5 5 16.47509 38.047385
6 6 19.80792 31.183069
7 7 17.44469 38.192385
8 8 18.78043 12.138436
9 10 15.68889 24.195719
10 11 17.39620 26.621287
11 15 16.71296 32.219763
By using tidyverse and pivot_longer you can merge the two variables. geom_col allows to define SU as the x-axis and the value of merged variable as the y-axis. The color is defined by fill=name where name is the merged column. Axis are renamed to make things clear.
library(tidyverse)
df <- read.table(text = " SU Mean_dbh Low_AGC
1 1 16.98921 17.696251
2 2 13.48199 8.108352
3 3 15.97746 14.584501
4 4 12.14046 28.910114
5 5 16.47509 38.047385
6 6 19.80792 31.183069
7 7 17.44469 38.192385
8 8 18.78043 12.138436
9 10 15.68889 24.195719
10 11 17.39620 26.621287
11 15 16.71296 32.219763", header=T)
df
#> SU Mean_dbh Low_AGC
#> 1 1 16.98921 17.696251
#> 2 2 13.48199 8.108352
#> 3 3 15.97746 14.584501
#> 4 4 12.14046 28.910114
#> 5 5 16.47509 38.047385
#> 6 6 19.80792 31.183069
#> 7 7 17.44469 38.192385
#> 8 8 18.78043 12.138436
#> 9 10 15.68889 24.195719
#> 10 11 17.39620 26.621287
#> 11 15 16.71296 32.219763
ggplot(df %>% pivot_longer(cols = Mean_dbh:Low_AGC),
aes(x=SU, y = value, fill=name)) +geom_col(position = 'dodge') +
labs(x='Location', y='Mean_dbh or Low_AGC') +
theme(legend.title = element_blank())

Multiple comparison after ANOVA - reordering factor levels post hoc test

I have a data frame with 15 factor levels:
Value <- runif(225)
df <- data.frame(Variant=rep(c(1:15), each=15),
Value=Value)
df$Variant <- factor(df$Variant)
levels(df$Variant)
I am using ANOVA and after Duncan test:
model <- lm(Value~Variant, data=df)
anova(model)
library(agricolae)
out <- duncan.test(model, "Variant", group=F); out
After Duncan test I get the following comparison order of factor levels:
1-10,1-11,1-12,1-13,1-14,1-15,1-2,1-3, 1-4, 1-5, 1-6, 1-7, 1-8, 1-9, 10-11, 10-12, 10-13, 10-14, 10-15 etc.
How can I manually change this order like this:
1-2,1-3, 1-4, 1-5, 1-6, 1-7, 1-8, 1-9, 1-10, 1-11, 1-12, 1-13, 1-14, 1-15, 2-1, 2-2, 2-3, 2-4, 2-5, 2-6 etc.
Thank You very much.
You can do
ord <- do.call(rbind, lapply(strsplit(row.names(out$comparison), " - "), as.numeric))
out$comparison[order(ord[,1], ord[,2]),]
#> difference pvalue signif. LCL UCL
#> 1 - 2 0.038843696 0.7161 -0.16755260 0.24523999
#> 1 - 3 -0.082464843 0.4965 -0.31294877 0.14801909
#> 1 - 4 -0.026633590 0.8112 -0.23991700 0.18664982
#> 1 - 5 -0.008944756 0.9333 -0.21534105 0.19745153
#> 1 - 6 -0.113440226 0.3555 -0.34762702 0.12074656
#> 1 - 7 -0.033132833 0.7772 -0.25544634 0.18918067
#> 1 - 8 -0.006618202 0.9470 -0.20269177 0.18945536
#> 1 - 9 0.046838403 0.6741 -0.16644500 0.26012181
#> 1 - 10 -0.091429309 0.4543 -0.32388649 0.14102787
#> 1 - 11 -0.140899981 0.2522 -0.37661897 0.09481900
#> 1 - 12 0.001178870 0.9906 -0.19489469 0.19725243
#> 1 - 13 -0.047673502 0.6884 -0.27319857 0.17785157
#> 1 - 14 -0.031176107 0.7857 -0.24953106 0.18717885
#> 1 - 15 -0.074161352 0.5370 -0.30236480 0.15404210
#> 2 - 3 -0.121308539 0.3226 -0.35549533 0.11287825
#> 2 - 4 -0.065477286 0.5752 -0.28779079 0.15683622
#> 2 - 5 -0.047788453 0.6766 -0.26614341 0.17056650
#> 2 - 6 -0.152283922 0.2177 -0.38937226 0.08480442
#> 2 - 7 -0.071976529 0.5492 -0.30017998 0.15622692
#> 2 - 8 -0.045461898 0.6831 -0.25874530 0.16782151
#> 2 - 9 0.007994707 0.9360 -0.18807886 0.20406827
#> 3 - 4 0.055831254 0.6330 -0.16648225 0.27814476
#> 3 - 5 0.073520087 0.5354 -0.15200498 0.29904515
#> 3 - 6 -0.030975383 0.7719 -0.23737167 0.17542091
#> 3 - 7 0.049332010 0.6577 -0.16395140 0.26261542
#> 3 - 8 0.075846641 0.5277 -0.15235681 0.30405009
#> 3 - 9 0.129303246 0.2943 -0.10641574 0.36502223
#> 4 - 5 0.017688833 0.8590 -0.17838473 0.21376240
#> 4 - 6 -0.086806636 0.4694 -0.31501009 0.14139682
#> 4 - 7 -0.006499243 0.9515 -0.21289553 0.19989705
#> 4 - 8 0.020015388 0.8514 -0.18638090 0.22641168
#> 4 - 9 0.073471993 0.5357 -0.15205307 0.29899706
#> 5 - 6 -0.104495470 0.3877 -0.33497940 0.12598846
#> 5 - 7 -0.024188077 0.8282 -0.23747148 0.18909533
#> 5 - 8 0.002326554 0.9814 -0.19374701 0.19840012
#> 5 - 9 0.055783160 0.6333 -0.16653035 0.27809667
#> 6 - 7 0.080307393 0.4913 -0.14200611 0.30262090
#> 6 - 8 0.106822024 0.3812 -0.12563515 0.33927920
#> 6 - 9 0.160278629 0.1961 -0.07804271 0.39859996
#> 7 - 8 0.026514631 0.8172 -0.19184032 0.24486959
#> 7 - 9 0.079971236 0.5097 -0.15051269 0.31045517
#> 8 - 9 0.053456605 0.6407 -0.16489835 0.27181156
#> 10 - 2 0.130273005 0.2906 -0.10544598 0.36599199
#> 10 - 3 0.008964466 0.9283 -0.18710910 0.20503803
#> 10 - 4 0.064795720 0.5852 -0.16072935 0.29032079
#> 10 - 5 0.082484553 0.4920 -0.14571890 0.31068801
#> 10 - 6 -0.022010917 0.8251 -0.21808448 0.17406265
#> 10 - 7 0.058296476 0.6107 -0.16005848 0.27665143
#> 10 - 8 0.084811107 0.4842 -0.14567282 0.31529504
#> 10 - 9 0.138267713 0.2641 -0.09882063 0.37535605
#> 10 - 11 -0.049470671 0.6431 -0.25586696 0.15692562
#> 10 - 12 0.092608180 0.4517 -0.14157861 0.32679497
#> 10 - 13 0.043755807 0.6944 -0.16952760 0.25703921
#> 10 - 14 0.060253203 0.6062 -0.16206030 0.28256671
#> 10 - 15 0.017267958 0.8716 -0.18912833 0.22366425
#> 11 - 2 0.179743677 0.1456 -0.05857766 0.41806501
#> 11 - 3 0.058435138 0.5995 -0.15484827 0.27171854
#> 11 - 4 0.114266391 0.3442 -0.11621754 0.34475032
#> 11 - 5 0.131955224 0.2776 -0.10050195 0.36441240
#> 11 - 6 0.027459755 0.7828 -0.16861381 0.22353332
#> 11 - 7 0.107767148 0.3617 -0.11775792 0.33329222
#> 11 - 8 0.134281779 0.2726 -0.09990501 0.36846857
#> 11 - 9 0.187738384 0.1296 -0.05170032 0.42717709
#> 11 - 12 0.142078851 0.2509 -0.09500949 0.37916719
#> 11 - 13 0.093226479 0.4236 -0.12908703 0.31553999
#> 11 - 14 0.109723874 0.3591 -0.11847958 0.33792733
#> 11 - 15 0.066738629 0.5597 -0.15161633 0.28509358
#> 12 - 2 0.037664826 0.7053 -0.15840874 0.23373839
#> 12 - 3 -0.083643714 0.4940 -0.31610089 0.14881346
#> 12 - 4 -0.027812460 0.8084 -0.24616741 0.19054249
#> 12 - 5 -0.010123627 0.9277 -0.22340703 0.20315978
#> 12 - 6 -0.114619097 0.3535 -0.35033808 0.12109989
#> 12 - 7 -0.034311704 0.7730 -0.25983677 0.19121336
#> 12 - 8 -0.007797073 0.9418 -0.21419336 0.19859922
#> 12 - 9 0.045659533 0.6690 -0.16073676 0.25205582
#> 12 - 13 -0.048852373 0.6848 -0.27705583 0.17935108
#> 12 - 14 -0.032354977 0.7823 -0.25466848 0.18995853
#> 12 - 15 -0.075340222 0.5347 -0.30582415 0.15514371
#> 13 - 2 0.086517198 0.4754 -0.14396673 0.31700113
#> 13 - 3 -0.034791341 0.7447 -0.24118763 0.17160495
#> 13 - 4 0.021039912 0.8503 -0.19224349 0.23432332
#> 13 - 5 0.038728746 0.7355 -0.17962621 0.25708370
#> 13 - 6 -0.065766724 0.5655 -0.28412168 0.15258823
#> 13 - 7 0.014540669 0.8839 -0.18153289 0.21061423
#> 13 - 8 0.041055300 0.7258 -0.18125821 0.26336881
#> 13 - 9 0.094511905 0.4391 -0.13794527 0.32696908
#> 13 - 14 0.016497396 0.8773 -0.18989890 0.22289369
#> 13 - 15 -0.026487850 0.7903 -0.22256141 0.16958571
#> 14 - 2 0.070019803 0.5552 -0.15550526 0.29554487
#> 14 - 3 -0.051288737 0.6544 -0.26964369 0.16706622
#> 14 - 4 0.004542517 0.9636 -0.19153105 0.20061608
#> 14 - 5 0.022231350 0.8352 -0.18416494 0.22862764
#> 14 - 6 -0.082264120 0.4877 -0.30778919 0.14326095
#> 14 - 7 -0.001956726 0.9843 -0.19803029 0.19411684
#> 14 - 8 0.024557904 0.8256 -0.18872550 0.23784131
#> 14 - 9 0.078014510 0.5159 -0.15018894 0.30621796
#> 14 - 15 -0.042985245 0.6996 -0.25626865 0.17029816
#> 15 - 2 0.113005048 0.3539 -0.11945213 0.34546222
#> 15 - 3 -0.008303492 0.9335 -0.20437706 0.18777007
#> 15 - 4 0.047527762 0.6783 -0.17082719 0.26588272
#> 15 - 5 0.065216595 0.5768 -0.15709691 0.28753010
#> 15 - 6 -0.039278874 0.7244 -0.25256228 0.17400453
#> 15 - 7 0.041028519 0.7009 -0.16536777 0.24742481
#> 15 - 8 0.067543150 0.5693 -0.15798192 0.29306822
#> 15 - 9 0.120999755 0.3239 -0.11318703 0.35518654
EDIT
The OP has asked how this might be achieved with Roman numerals. In that case, you would need to do:
install.packages("gtools")
ord <- do.call(rbind,
lapply(strsplit(row.names(out$comparison), "\\W"),
function(x) gtools::roman2int(x[x != ""])))
out$comparison[order(ord[,1], ord[,2]),]

coreNLP- r package annotateString gives Null openie

I am new in using the R coreNLP package. I just installed the package with the objective to use the function getOpenIE. However, even when I run the code on a very simple sentence.The annotateString function doesn't work for annotating openie. See the below code:
library(coreNLP)
downloadCoreNLP()
initCoreNLP()
text <- "food is good and staff is friendly"
t <- annotateString(text)
> t$openie
NULL
> getOpenIE(t)
NULL
Is this a common issue? has anyone found a solution yet? Thank you
I had trouble with this too. You need to addtype = "english_all" when using the initCoreNLP function. See a working reprex below:
library(coreNLP)
#> Warning: package 'coreNLP' was built under R version 3.4.4
downloadCoreNLP()
#> [1] 0
initCoreNLP(type = "english_all")
text <- "food is good and staff is friendly"
t <- annotateString(text)
t$openie
#> subject_start subject_end subject relation_start relation_end relation
#> 1 4 5 staff 5 6 is
#> 2 0 1 food 1 2 is
#> object_start object_end object
#> 1 6 7 friendly
#> 2 2 3 good
getOpenIE(t)
#> subject_start subject_end subject relation_start relation_end relation
#> 1 4 5 staff 5 6 is
#> 2 0 1 food 1 2 is
#> object_start object_end object
#> 1 6 7 friendly
#> 2 2 3 good
Created on 2018-12-29 by the reprex package (v0.2.1)

Resources