我有一个包含用户GPS位置的.csv文件。一列称为位置存储,其包含用户的15个经度和纬度。位置存储内容的示例如下:
121.49961,25.023201;121.499596,25.023188;121.49961,25.02319;121.4996,25.023182;121.4996,25.023184;121.4996,25.023184;121.4996,25.023174;121.4996,25.023167;121.49959,25.02316;121.49959,25.023146;121.499565,25.023125;121.499565,25.023117;121.49958,25.023111;121.499596,25.023132;121.4996,25.023123
121.5011,25.02951;121.5011,25.02951;121.50063,25.029524;121.500534,25.029497;121.50069,25.029512;121.50069,25.029512;121.50069,25.029512;121.50069,25.029512;121.50069,25.029512;121.50069,25.029512;121.50069,25.029512;121.50069,25.029512;121.50069,25.029512;121.50069,25.029512;121.50069,25.029512
121.50069,25.029512;121.50069,25.029512;121.50069,25.029512;121.50069,25.029512;121.50069,25.029512;121.50069,25.029512;121.50069,25.029512;121.50069,25.029512;121.50069,25.029512;121.50069,25.029512;121.50069,25.029512;121.50069,25.029512;121.50069,25.029512;121.50069,25.029512;121.50069,25.029512
...
我想用R从.csv文件中提取最后一对经度和纬度,我该怎么做?谢谢。
到目前为止,我已完成以下步骤:
Trip1 <- read.csv("1.csv", sep = ",", header = TRUE)
Trip1$location_store
head(Trip1$location_store)
LocationTemp <-strsplit(as.character(Location), ";")
LocationTemp
...
[[176]]
[1] "121.52448,25.073643" "121.52452,25.073673" "121.524574,25.07372"
[4] "121.524635,25.073753" "121.5247,25.073814" "121.524765,25.07385"
[7] "121.52485,25.073881" "121.524925,25.073938" "121.52499,25.073973"
[10] "121.52507,25.074041" "121.52514,25.074095" "121.525185,25.074121"
[13] "121.525215,25.074146" "121.52523,25.074142" "121.52524,25.074146"
[[177]]
[1] "121.52526,25.07417" "121.525276,25.074173" "121.52529,25.074173"
[4] "121.52529,25.07418" "121.52529,25.074183" "121.52529,25.074183"
[7] "121.52529,25.07418" "121.5253,25.074179" "121.5253,25.074183"
[10] "121.5253,25.074188" "121.5253,25.074186" "121.52531,25.074186"
[13] "121.52531,25.074188" "121.52531,25.074186" "121.52531,25.074186"
[[178]]
[1] "121.52531,25.074186" "121.52531,25.074186" "121.525314,25.074188"
[4] "121.525314,25.07419" "121.525314,25.074188" "121.525314,25.074188"
[7] "121.525314,25.074188" "121.525314,25.074188" "121.525314,25.074188"
[10] "121.525314,25.074188" "121.525314,25.074188" "121.525314,25.074188"
[13] "121.525314,25.074188" "121.525314,25.074188" "121.525314,25.074188"
...
但是,我不知道提取最后一对经度和纬度值。
答案 0 :(得分:0)
虽然它有点草率,但这应该从你当前的代码中得到你想要的东西。
last_values_per_user <- lapply(1:length(LocationTemp),
function(i) unlist(strsplit(LocationTemp[[i]][[15]],","))